领域字符串大于 [英] Realm String greaterThan
本文介绍了领域字符串大于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么方法可以找到所有(或仅下一个)在字典上大于目标的字符串的RealmObject
吗?
Is there any way to find all (or just the next) RealmObject
s with Strings lexicographically greater than the target?
类似
MyEntry next = realm.where(MyEntry.class)
.greaterThan("name", current)
.findAllSorted("name")
.first();
无效,因为greaterThan
未针对String
实施.
which did not work, because greaterThan
is not implemented for String
s.
推荐答案
作为非数据库替代方法,您可以使用
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.
这篇关于领域字符串大于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文