Is there a java equivalent to NSPredicate?

假装没事ソ 提交于 2019-12-13 16:35:42

问题


I am writing something in java that will try to "autocomplete" what a user is typing. I have used NSPredicate on iPhone apps to do this. It was very easy and worked well. I am hoping that there is something similar in java, but not having much luck finding it.

If something does not already exist to do this in java, does anyone have any suggestions on the best approach? I'm thinking of maybe doing something like having a Map with the key being "A", "B", "C", ... and the value being a list of sorted data that starts with the corresponding letter in order to get more manageable size lists and then iterating that list to find matches as each letter is typed.

Any other suggestions would be appreciated.

Thanks


回答1:


You have not provided enough information. Is the list, against which you are autocompleting (henseforth referred to as the "target list", a static list of values? If yes, look at String.startsWith() and maybe the Comparator interface for searching the list.

If the target list is the result of a query, then structure your query to use partial matching (in oracle, you would have a where clause of "like 'xxx%'" xxx being the partial value and % being the oracle token for "match anything").



来源:https://stackoverflow.com/questions/3790453/is-there-a-java-equivalent-to-nspredicate

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