1for (Map.Entry<String, String> entry : yourHashMap.entrySet()) {
2 System.out.println(entry.getKey() + " = " + entry.getValue());
3}
1for (Map.Entry<String, String> entry : yourHashMap.entrySet()) {
2 System.out.println(entry.getKey() + " = " + entry.getValue());
3}
4
5map.forEach((k, v) -> {
6 System.out.format("key: %s, value: %d%n", k, v);
7});
1Map<String, String> map = new HashMap<>();
2
3for(Entry<String, String> entry:map.entrySet()) {
4 System.out.println("key: "+entry.getKey()+" value: "+entry.getValue());
5}
1for (Map.Entry<String, Object> entry : map.entrySet()) {
2 String key = entry.getKey();
3 Object value = entry.getValue();
4 // ...
5}
1public static void printMap(Map mp) {
2 Iterator it = mp.entrySet().iterator();
3 while (it.hasNext()) {
4 Map.Entry pair = (Map.Entry)it.next();
5 System.out.println(pair.getKey() + " = " + pair.getValue());
6 it.remove(); // avoids a ConcurrentModificationException
7 }
8}
1public static void printMap(Map mp) {
2 Iterator it = mp.entrySet().iterator();
3 while (it.hasNext()) {
4 Map.Entry pair = (Map.Entry)it.next();
5 System.out.println(pair.getKey() + " = " + pair.getValue());
6 it.remove(); // avoids a ConcurrentModificationException
7 }
8}
9