-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForeachListLambda.java
More file actions
43 lines (33 loc) · 1.02 KB
/
Copy pathForeachListLambda.java
File metadata and controls
43 lines (33 loc) · 1.02 KB
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
36
37
38
39
40
41
42
43
package java8.lambda;
import java.util.ArrayList;
import java.util.List;
/**
* @Author : yion
* @Date : 2016. 8. 19.
* @Description : https://www.mkyong.com/java8/java-8-foreach-examples/
* ClassicListDemo -> Lambda 변환
*/
public class ForeachListLambda {
public static void main(String[] args) {
List<String> items = new ArrayList<>();
items.add("A");
items.add("B");
items.add("C");
items.add("D");
items.add("E");
System.out.println("lambda ");
items.forEach(item -> System.out.println("item : " + item));
System.out.println("lambda condition ");
items.forEach(item -> {
if ("C".equals(item)) {
System.out.println(item);
}
});
System.out.println("method reference");
items.forEach(System.out::println);
System.out.println("Stream and filter");
items.stream()
.filter(s -> s.contains("B"))
.forEach(System.out::println);
}
}