-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForEachMapLambda.java
More file actions
35 lines (28 loc) · 941 Bytes
/
Copy pathForEachMapLambda.java
File metadata and controls
35 lines (28 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package java8.lambda;
import java.util.HashMap;
import java.util.Map;
/**
* @Author : yion
* @Date : 2016. 8. 19.
* @Description : https://www.mkyong.com/java8/java-8-foreach-examples/ 예제
* ClassicMapDemo.java -> ForEach Lambda 변환
*/
public class ForEachMapLambda {
// In Java 8, you can loop a Map with forEach + lambda expression.
public static void main(String[] args) {
Map<String, Integer> items = new HashMap<>();
items.put("A", 10);
items.put("B", 20);
items.put("C", 30);
items.put("D", 40);
items.put("E", 50);
items.put("F", 60);
items.forEach((k , v) -> System.out.println("normal Item : " + k + " Count : " + v));
items.forEach((k, v) -> {
System.out.println("Condition Item : " + k + " Count : " + v);
if ("E".equals(k)) {
System.out.println("Hello E");
}
});
}
}