forked from Rapter1990/JavaStreamAPIExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortedDistinctFlow.java
More file actions
38 lines (30 loc) · 1.47 KB
/
SortedDistinctFlow.java
File metadata and controls
38 lines (30 loc) · 1.47 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
package functionalexamples;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
public class SortedDistinctFlow {
public static void main(String[] args) {
Locale.setDefault(Locale.forLanguageTag("en-US"));
List<String> names = Arrays.asList("Sergio","Sunil","Ana","Michelle",
"Sunil","Sergio","Anita");
List<String> result =
names.stream()
.peek(e->System.out.println("Going to filter: " + e))
.filter(name -> name.length() >3)
.peek(e->System.out.println("Going to distinct: " + e))
.distinct()
.peek(e->System.out.println("Going to sort: " + e))
.sorted()
.peek(e->System.out.println("Done with sorting: " + e))
// .peek(e->System.out.println("Going to take distinct elements: " + e))
// .distinct()
// .peek(e -> System.out.println("Done with distinct"))
.peek(e->System.out.println("Going to map: " + e))
.map(name -> name.toUpperCase())
.peek(e->System.out.println("Going to collect: " + e))
.collect(Collectors.toList());
System.out.println("Result is "+result);
System.out.println("Original list is "+names);
}
}