我有一个HashMap<Integer,String>
. 我尝试了以下代码来查询地图并返回所有可能的值
public Collection<String> query(String queryStr) {
List<String> list = new ArrayList<String>();
for (Map.Entry<String, Integer> entry : myMap.entrySet()) {
if (queryStr.matches(entry.getKey()))
list.add(entry.getKey());
}
if (list.isEmpty())
return null;
else
return list;
}
如果地图有"test","best","crest","zest","testy","tether","temper","teat","tempest"
. te*t
应该返回的查询"teat","tempest","test"
。对于“test*”,它应该返回“test”、“testy”。如何实施?是否有任何通配符搜索字符串?而且我不能使用任何外部库。