What is the easiest way to iterate over all the key/value pairs of a java.util.Map in Java 5 and higher?
25,595
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
}
Author by
flybywire
Updated on June 21, 2020Comments
-
flybywire almost 4 years
What is the easiest way to iterate over all the key/value pairs of a java.util.Map in Java 5 and higher?