February 2014
Beginner
1248 pages
62h 25m
English
Figure 17.14 uses Stream method collect (line 95) to group Employees by department. Method collect’s argument is a Collector that specifies how to summarize the data into a useful form. In this case, we use the Collector returned by Collectors static method groupingBy, which receives a Function that classifies the objects in the stream—the values returned by this function are used as the keys in a Map. The corresponding values, by default, are Lists containing the stream elements in a given category. When method collect is used with this Collector, the result is a Map<String, List<Employee>> in which each String key is a department and each List<Employee> contains the Employees in that department. We assign ...
Read now
Unlock full access