我希望使用 copyFromRealm 方法将内存中的前10行或可能n行作为java列表。考虑这样:
RealmResults<RecentViewItem> results = realm.where(RecentViewItem.class).findAllSorted("updatedAt", Sort.DESCENDING);
// This will load all rows in-memory list
List<RecentViewItem> list = realm.copyFromRealm(results);
// But I want only first n rows without running any loop.
更新 由于RealmResult扩展了AbstractList -
RealmResults<RecentViewItem> results =
realm.where(RecentViewItem.class)
.findAllSorted("updatedAt", Sort.DESCENDING);
List<RecentViewItem> temp = results.subList(0, maxNoRecentViewItem); // Still list of RealmProxyObject
List<RecentViewItem> list = realm.copyFromRealm(temp); // List of RecentViewItem Object