Realm String greaterThan

别说谁变了你拦得住时间么 提交于 2019-12-01 07:31:11

问题


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

Something like

MyEntry next = realm.where(MyEntry.class)
        .greaterThan("name", current)
        .findAllSorted("name")
        .first();

which did not work, because greaterThan is not implemented for Strings.


回答1:


As a non-db-workaround, you can use

List<MyEntry> 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.



来源:https://stackoverflow.com/questions/44581878/realm-string-greaterthan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!