我正在尝试像这样迭代 HashMap:
for (Map.Entry<String, Integer> entry : map.entrySet()) {
String key = entry.getKey();
Integer value = entry.getValue();
}
但我收到此错误:
entry cannot be resolved
这是错误的做法吗?据我所知,这似乎对其他人也有效。
最佳答案
您应该使用迭代器
。 Check out the docs
关于java - Java 中遍历 HashMap 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18517715/