如何在java中的哈希映射中的sql中搜索LIKe运算符 [英] how to search like LIKe operator in sql in hash map in java
本文介绍了如何在java中的哈希映射中的sql中搜索LIKe运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想根据用户输入搜索哈希映射。假设用户给出值'A',我必须以公司名称开头显示,如果用户给出值'AB',我必须以AB公司名称开头。我在哈希映射中存储公司名称
I want to search a hash map depending on the user input. Suppose a user give value 'A',I have to display starting with A company name and if user give value 'AB' I have to display starting with AB company name. I am storing company name in hash map
推荐答案
-
使用 NavigableSet 。
示例:
NavigableSet<String> company=new TreeSet<String>();
Set<String> filteredSet=company.tailSet(prefix);
for(String str:filteredSet) {
if(str.startsWith(prefix))
//add to list
else
break;
}
Use a radix tree [wiki] or trie [wiki] if you are concerned about performance.The radix tree is more memory efficient compared to a trie.
这篇关于如何在java中的哈希映射中的sql中搜索LIKe运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文