February 2014
Beginner
1248 pages
62h 25m
English
Figure 17.15 once again demonstrates Stream method collect and Collectors static method groupingBy, but in this case we count the number of Employees in each department. Lines 107–110 produce a Map<String, Long> in which each String key is a department name and the corresponding Long value is the number of Employees in that department. In this case, we use a version of Collectors static method groupingBy that receives two arguments—the first is a Function that classifies the objects in the stream and the second is another Collector (known as the downstream Collector). In this case, we use a call to Collectors static method counting as the second argument. This method returns a Collector ...
Read now
Unlock full access