Realm String greaterThan

后端 未结 1 1476
名媛妹妹
名媛妹妹 2021-01-14 04:26

Is there any way to find all (or just the next) RealmObjects with Strings lexicographically greater than the target?

Something like

MyE         


        
1条回答
  •  有刺的猬
    2021-01-14 05:17

    As a non-db-workaround, you can use

    List l = realm.where(MyEntry.class)
        .findAllSorted("name");
    int pos = l.indexOf(entryWithName);
    MyEntry next = l.get((pos+1)%l.size());
    

    This does the searching outside of the db. Possibly not as well-performing, and not as readable, but it should work.

    0 讨论(0)
提交回复
热议问题