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});
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}
1for(Map.Entry<String, Integer> entry : hashMap.entrySet()) {
2 String key = entry.getKey();
3 Integer value = entry.getValue();
4 //do something with the key and value
5}
1Map<Integer, Integer> map = new HashMap<Integer, Integer>();
2for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
3 System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
4}
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