/home/oracle/labs/06CollectionOperations/examples/EmployeeSearch/src/com/example/lambda/A14CollectGrouping.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 oracle
11  */
12 public class A14CollectGrouping {
13     
14     public static void main(String[] args) {
15         
16         List<Employee> eList = Employee.createShortList();
17         
18         Map<String, List<Employee>> gMap = new HashMap<>();
19        
20         // Collect CO Executives
21         gMap = eList.stream()
22             .collect(Collectors.groupingBy(Employee::getDept));        
23 
24         System.out.println("\n== Employees by Dept ==");
25         gMap.forEach((k,v) -> {
26             System.out.println("\nDept: " + k); 
27             v.forEach(Employee::printSummary);
28         });
29                 
30     }
31     
32 }
33