What is the easiest way to iterate over all the key/value pairs of a java.util.Map in Java 5 and higher?
在Java 5及更高版本中迭代java.util.Map的所有键/值对的最简单方法是什么?
1 个解决方案
#1
69
Assuming K
is your key type and V
is your value type:
假设K是您的密钥类型,V是您的值类型:
for (Map.Entry<K,V> entry : map.entrySet()) {
K key = entry.getKey();
V value = entry.getValue();
// do stuff
}
#1
69
Assuming K
is your key type and V
is your value type:
假设K是您的密钥类型,V是您的值类型:
for (Map.Entry<K,V> entry : map.entrySet()) {
K key = entry.getKey();
V value = entry.getValue();
// do stuff
}