1Map<String, Integer> items = new HashMap<>();
2items.put("A", 10);
3items.put("B", 20);
4items.put("C", 30);
5items.put("D", 40);
6items.put("E", 50);
7items.put("F", 60);
8
9items.forEach((k,v)->System.out.println("Item : " + k + " Count : " + v));
10
11items.forEach((k,v)->{
12 System.out.println("Item : " + k + " Count : " + v);
13 if("E".equals(k)){
14 System.out.println("Hello E");
15 }
16});
1public void iterateUsingStreamAPI(Map<String, Integer> map) {
2 map.entrySet().stream()
3 // ...
4 .forEach(e -> System.out.println(e.getKey() + ":" + e.getValue()));
5}
6