Quick Answer
Collectors.groupingBy(classifier) groups stream elements into a Map>. Downstream collectors change the value: groupingBy(Person::getDept, counting()) gives Map. groupingBy(Person::getDept, toList()) is the default. Multi-level grouping: groupingBy(getDept, groupingBy(getCity)). toMap(keyMapper, valueMapper) for custom key-value extraction.
Answer
groupingBy groups data by a key. Supports downstream collectors like counting, summing, mapping. Useful for analytics and reports.
S
SugharaIQ Editorial Team
Verified Answer
This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.