-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollect.java
39 lines (31 loc) · 2.09 KB
/
collect.java
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 com.JAVA8.TerminalFunctions;
import java.util.List;
import java.util.stream.Collectors;
import com.JAVA8.model.Employee;
public class collect {
public static void main(String[] args) {
List<Employee> list=List.of(new Employee("sai", "[email protected]", 1234567890L, "india" , 50000.0), new Employee("chiranjeevi", "[email protected]", 9087654321L,"US", 25000.0),
new Employee("Nooruddin", "[email protected]",8328474317L, "india", 52500.0),new Employee("samiulla", "[email protected]", 9030505333L, "italy", 100000.0),
new Employee("Noorjahan", "[email protected]", 8466909090L, "arab", 40000.0),new Employee("Zammruth", "[email protected]", 9398762600L, "japan", 7000),
new Employee("baji", "[email protected]", 8690248234L, "chaina", 15000.0),new Employee("asif", "[email protected]", 8214324567L, "paris", 25000.0),
new Employee("Abhi", "[email protected]", 9898765679L, "africa", 25000.0),new Employee("rohit", "[email protected]", 678901234L, "india", 50000.0),
new Employee("satyaBratha", "[email protected]", 7890654321L, "German", 70000.0),new Employee("Twinkle", "[email protected]", 9977885467L, "IceLand", 150000.0),new Employee("Twinkle", "[email protected]", 9977885467L, "IceLand", 150000.0));
System.out.println(list.parallelStream()
.collect(Collectors.
groupingBy(Employee::getSalary,
Collectors.mapping(Employee::getName,Collectors.toList()))));
System.err.println(list.parallelStream()
.collect(Collectors.
groupingBy(Employee::getSalary,
Collectors.mapping(Employee::getEmail,Collectors.toUnmodifiableSet()))));
System.out.println(list.parallelStream()
.collect(Collectors
.groupingBy(Employee::getCountry,
Collectors.mapping(Employee::getName, Collectors.toList()))));
System.err.println(list.parallelStream()
.collect(Collectors
.partitioningBy(e->e.getSalary() >= 100000.0
,Collectors.mapping(Employee::getName, Collectors.toUnmodifiableList()))));
System.out.println(list.stream().collect(Collectors.mapping(Employee::getName, Collectors.toSet())));
}
}