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