This example shows how to sort Realm results object in ascending or descending order using Java RealmResults sort() method query with keyword parameter.
— Sorting Objects in RealmResults using sort() method – Realm Database Query
1 2 3 4 5 6 7 8 9 10 11 12 |
try (Realm realm = Realm.getDefaultInstance()) { // Obtain the results of a query RealmResults results = realm.where(Model.class).findAll(); // Default sort ascending results = results.sort("firstname"); // Sort descending results = results.sort("firstname", Sort.DESCENDING); } |