Section 17.6.6 Counting the Number of Employees in Each Department

Collectors static method groupingBy with two arguments receives a Function that classifies the objects in the stream and another Collector (known as the downstream Collector; p. 756).

Collectors static method counting returns a Collector that counts the number of objects in a given classification, rather than collecting them into a List.

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.