forked from andyczy/czy-study-java-commons-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleList.java
More file actions
39 lines (36 loc) · 1 KB
/
ExampleList.java
File metadata and controls
39 lines (36 loc) · 1 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
package lambda;
import java.util.ArrayList;
import java.util.List;
/**
* @Auther 陈郑游
* @Data 2017/8/21 0021
* @Description: http://www.cnblogs.com/wangdaijun/p/6287532.html
* @CSDN:http://blog.csdn.net/javawebrookie
* @GITHUB:https://github.com/AndyCZY
*/
public class ExampleList {
private static List<String> items = new ArrayList<>();
static {
items.add("A");
items.add("BC");
items.add("C");
items.add("BD");
items.add("E");
}
public static void main(String[] args) {
//Java8之前操作List
for(String item:items){
System.out.println(item);
}
//Java8 lambda遍历list
items.forEach(c-> System.out.println(c));
items.forEach(item->{
if("C".equals(item)){
System.out.println(item);
}
});
System.out.println("--------");
//先过滤
items.stream().filter(s->s.contains("B")).forEach(c1-> System.out.println(c1));
}
}