领域删除除一个以外的所有内容table

Realm delete all except one table

这是领域Java所以我在做

realm.beginTransaction();
realm.deleteAll();
realm.commitTransaction();

我有 20 个左右 Realm 类。 我只想留一个

而不是做

realm.beginTransaction();
  realm.delete(Table1.class);
  realm.delete(Table2.class);
  realm.delete(Table3.class);
  ...
realm.commitTransaction();

有没有办法删除除一个表之外的所有表?

"deleteAll.except(Table12.class)" 等?

谢谢!

当然可以!

final RealmConfiguration realmConfiguration = realm.getConfiguration();
r.executeTransaction((realm) -> {
    for(Class<? extends RealmModel> clazz : realmConfiguration.getRealmObjectClasses()) {
        if(clazz != Table12.class) {
            realm.delete(clazz);
        }
    }
});