enter image description here我有一个 HashMap ,我需要将字符串数组的值与某些字符串进行比较并删除那些相等的值。在本例中,我知道某个索引处的 String [] = "RES",但是当我迭代 if(相等)语句时,每次都会返回 false。在简单地扩展 hashmap 时,我是否需要担心覆盖 .equals() ? if 语句有什么问题?
public void filter(){
Iterator<Map.Entry<String, String[]>> iter = this.entrySet().iterator();
while(iter.hasNext()){
Map.Entry<String,String[]> entry = iter.next();
String[] current = entry.getValue();
if(current[0].trim().equalsIgnoreCase("RES")){
this.remove(entry.getKey());
}
}
}
最佳答案
替换:
this.remove(entry.getKey());
与:
iter.remove();
关于java - .Equals() 在迭代 HashMap 时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39963165/