问题描述
目前我使用的是 HashMap< String,Integer>
,它是用 String
类型的键填充的,比方说,5个字符长。如何搜索4个字符或更少的特定密钥,这些密钥是其中一部分和其他一些密钥的开头,并将所有匹配作为< Key,Value> $ c $的集合进行搜索除非您创建自定义数据结构,否则迭代是您的唯一选项:
$
if(e.getKey()。startsWith(xxxx)b $ b
){
//添加到我的结果列表中
}
}
如果您需要更多时间效率的东西,那么您需要在地图上实现跟踪这些部分键的地方。
I am currently using HashMap<String, Integer>
which is filled with keys of type String
which are all, let's say, 5 chars long. How can I search for an specific key of 4 chars or less, which is part and at the beginning of some other keys and get all hits as a collection of <Key, Value>
?
Iterate is your only option unless you create a custom data structure:
for (Entry<String, Integer> e : map.entrySet()) {
if (e.getKey().startsWith("xxxx")) {
//add to my result list
}
}
If you need something more time efficient then you'd need an implementation of map where you are tracking these partial keys.
这篇关于HashMap< String,Integer>搜索密钥的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!