How to sort the RealmResults with recents dates?

Raja Jawahar picture Raja Jawahar · Apr 13, 2016 · Viewed 12.4k times · Source

I have around 20 rows in RealmResults and need to sort the list with recent dates

RealmConfiguration realmConfig = new RealmConfiguration.Builder(getActivity()).build();
Realm realm = Realm.getInstance(realmConfig);

Like below

RealmResults<MyTable> List = realm.where(MyTable.class).findAll().sort("date",SORT.DESCENDING);

Answer

EpicPandaForce picture EpicPandaForce · Apr 13, 2016

It's really just the following.

RealmResults<MyTable> list = realm.where(MyTable.class)
                                .findAllSorted("date",Sort.DESCENDING);

And since 4.3.x:

RealmResults<MyTable> list = realm.where(MyTable.class)
                      .sort("date",Sort.DESCENDING)
                      .findAll();