What is the easiest way to iterate over all the key/value pairs of a java.util.Map in Java 5 and higher?
views:
545answers:
1
+19
A:
Assuming K
is your key type and V
is your value type:
for (Map.Entry<K,V> entry : map.entrySet()) {
K key = entry.getKey();
V value = entry.getValue();
// do stuff
}
Joachim Sauer
2009-02-25 11:39:26