forked from 1399852153/Streamjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestJDKStream.java
More file actions
37 lines (32 loc) · 1.25 KB
/
Copy pathTestJDKStream.java
File metadata and controls
37 lines (32 loc) · 1.25 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
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Author xiongyx
* on 2019/3/5.
*/
public class TestJDKStream {
public static void main(String[] args){
List<String> teamIndia = Arrays.asList("11", "12", "13");
List<String> teamAustralia = Arrays.asList("21", "22", "23","24");
List<String> teamEngland = Arrays.asList("31", "32", "33");
List<String> teamNewZeland = Arrays.asList("41", "42", "43");
List<String> teamSouthAfrica = Arrays.asList("52", "53");
List<List<String>> playersInWorldCup2016 = new ArrayList<>();
playersInWorldCup2016.add(teamIndia);
playersInWorldCup2016.add(teamAustralia);
playersInWorldCup2016.add(teamEngland);
playersInWorldCup2016.add(teamNewZeland);
playersInWorldCup2016.add(teamSouthAfrica);
// Now let's do this in Java 8 using FlatMap
playersInWorldCup2016.stream()
.flatMap(pList -> pList.stream())
.filter(item->item.endsWith("4"))
.limit(3)
.peek(System.out::println)
.collect(Collectors.toList())
.forEach(System.out::println);
Runnable r = ()->{};
}
}