How to get first n rows in-memory from realm

1.3k views Asked by At

I want to get only first 10 or possibly n rows in-memory as java list using copyFromRealm method. Consider like this:

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.

UPDATE: Since RealmResult extends 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
0

There are 0 answers