Search code examples
javaandroidrealm

how to convert RealmList<T> to RealmResults<T>


I am working on realm database and want to convert RealmList to RealmResults. The realmlist is attribute of realm object.


Solution

  • Simple use query on your list :

    class MyObject extends RealmObject {
    
        RealmList<MySubObject> subObjects;
    }
    
    ...
    
    myObject.subObjects.where().findAll(); //returns a RealmResults
    
    //you can query your list like
    myObject.subObjects
         .where()
         .equalTo("status", "done")
         .findAll(); //you can use sort, findFirst etc