我正在尝试使用 entrySet() 迭代嵌套的哈希图。Multi-hashmap 称为数据,我试图在它包含的许多哈希图中搜索一个值。然而,即使我似乎到达了正确的地方,它与我的搜索词不匹配。当我打印这些值时,我看到搜索词确实是当前循环中的哈希图中的值之一。这是代码 -
HashMap<String,HashMap<String,String>> data = driver.data.get(dsName);
for (int i = 0; i < arrWhereValues.length; i++) {
String value = null;
for (Entry<String, HashMap<String, String>> entry : data.entrySet()) {
System.out.println("VALUE:::" +entry.getValue());
System.out.println("SEARCH FOR::"+arrWhereValues[i]);
if(arrWhereValues[i].equals(entry.getKey())){
value = entry.getKey();
System.out.println("Value in case 1::" +value);
}
else if(entry.getValue().containsValue(arrWhereValues[i])){ //Why doesn't it enter here???
System.out.println("atleast this much was correct!!");
System.out.println(entry.getValue().entrySet());
for (Entry<String, String> v : entry.getValue().entrySet()) { //Find a better way of doing this.
if(v.getValue().contains(arrWhereValues[i])){
value = v.getKey();
System.out.println("Value in case 2 ::"+value);
}
}
}
}
输出:
VALUE:::{name=Testing User , slug_primary=null, slug_secondary=null}
SEARCH FOR::Testing User
我究竟做错了什么?