How do Collectors.groupingBy and partitioningBy work? What is a downstream collector?
Short answer
groupingBy splits elements into groups, like GROUP BY in SQL. partitioningBy splits in two by a condition and always has both true and false groups.
3 points to say:
- The default result is
Map<Key, List<T>>. - The second argument decides what each group becomes, like
counting(). - An empty group still has its key in
partitioningBy.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.