【发布时间】:2017-04-11 09:41:58
【问题描述】:
我有一个 HashMap。我想检查我的单个数组列表(nodeList)值是否包含在我的 HashMap 的值中。为了访问我的地图中给定方式元素的节点值,我使用了 getNodes 方法,它的输出如下:
getNodes() 返回一个列表输出:[元素 N847744431 ({}),元素 N847744763 ({})]
public class RoadNetwork{
public void checkContent(){
for(int i =0; i < nodeList.size(); i++){
/* Does node(i) belong in the valueList of Way? */
Set<Map.Entry<String, Element>> entrySet = wayList.entrySet();
for (Map.Entry entry : entrySet){
Way w1 = (Way) wayList.get(entry.getKey());
//Check if Way contains node(i)
if(w1.getNodes().contains(nodeList.get(i))){
System.out.println("Found something");
}
}
}
}
}
public class Way{
public List<Node> getNodes(){
return nodes;
}
}
我可以做些什么来解决这个问题,我想检查我的 hashmap 中的给定值,但是 .contains() 方法在这种情况下不起作用。
【问题讨论】:
-
请提供minimal reproducible example(并尽可能格式化)而不仅仅是sn-ps。请注意,在
HashMap中搜索 值 会破坏HashMap的很多意义...它针对 key 查找进行了优化。 -
没有问题..