我这里有 LinkHashMap。
Map<String, String> map
{011A=HongKong, 012B=London, 015Y=NewYork, 312=China, 272=Canada}
我想将 map 过滤或排列成这样,
map 中仅保留 3 位数字或长度 = 3 的 key 。
{312=China, 272=Canada}
我可以使用什么样的方法? 非常感谢!
最佳答案
您可以使用Iterator
Iterator<String> it = map.keySet().iterator();
while (it.hasNext())
{
String s = it.next();
if(s.length() != 3){
it.remove();
}
}
关于java - 如何过滤Map中只有3个字符串长度的键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53428617/