Section 17.6.5 Grouping Employees By Department
• Collectors static
method groupingBy
(p. 755) with one argument receives a Function
that classifies objects in the stream—the values returned by this function are used as the keys in a Map
. The corresponding values, by default, are List
s containing the stream elements in a given category.
• Map
method forEach
performs an operation on each key–value pair. The method receives an object that implements functional interface BiConsumer
. This interface’s accept
method has two parameters. For Map
s, the first represents the key and the second the corresponding value.
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.