| /home/oracle/labs/06CollectionOperations/examples/EmployeeSearch/src/com/example/lambda/A16CollectPartition.java |
1 package com.example.lambda;
2
3 import java.util.HashMap;
4 import java.util.List;
5 import java.util.Map;
6 import java.util.stream.Collectors;
7
8
9
10 @author
11
12 public class A16CollectPartition {
13
14 public static void main(String[] args) {
15
16 List<Employee> eList = Employee.createShortList();
17
18 Map<Boolean, List<Employee>> gMap = new HashMap<>();
19
20
21 gMap = eList.stream()
22 .collect(
23 Collectors.partitioningBy(
24 e -> e.getRole().equals(Role.EXECUTIVE)));
25
26 System.out.println("\n== Employees by Dept ==");
27 gMap.forEach((k,v) -> {
28 System.out.println("\nGroup: " + k);
29 v.forEach(Employee::printSummary);
30 });
31
32 }
33
34 }
35