July 2023
Intermediate to advanced
276 pages
6h 55m
English
In Using the collect Method and the Collectors Class, you saw the amazing capabilities of the groupingBy function and the mapping function to split a collection into different groups. We got a taste of the recursive nature of the Collector there. The collect method takes a Collector as a parameter. We can pass the response from calling groupingBy, for example. But we saw a variation where we passed the result of a call to the mapping method as the second argument to groupingBy. Then again, the mapping function itself expects a Collector as its second argument. This recursive structure is mind-blowing:
| | //pseudocode |
| | ...stream() |
| | .collect(groupingBy(...)) //collect takes a Collector |
| | |
| | or |
| | |
| | ...stream() |
| | .collect(groupingBy(..., ... |
Read now
Unlock full access