Logo

Programming-Idioms

History of Idiom 13 > diff from v19 to v20

Edit summary for version 20 by :

Version 19

2015-09-13, 12:12:52

Version 20

2015-09-13, 12:15:32

Idiom #13 Iterate over map keys and values

Print each key k with its value x from an associative array mymap

Idiom #13 Iterate over map keys and values

Print each key k with its value x from an associative array mymap

Code
for (Map.Entry<Object, Object> entry : mymap.entrySet()) {
    Object k = entry.getKey();
    Object x = entry.getValue();
    System.out.println("Key=" + k + ", Value=" + x);
}
Code
for (Map.Entry<Object, Object> entry : mymap.entrySet()) {
    Object k = entry.getKey();
    Object x = entry.getValue();
    System.out.println("Key=" + k + ", Value=" + x);
}
Comments bubble
Instead of Object, prefer using sensible key type and value type.
Origin
http://stackoverflow.com/questions/1066589/java-iterate-through-hashmap#answer-1066607
Origin
http://stackoverflow.com/questions/1066589/java-iterate-through-hashmap#answer-1066607