The java.util.stream.Collectors utility class provides a powerful suite of reduction operations that transform stream results into collections, maps, groups, partitions, and statistical summaries. Essential Collector Functions Collector Return Type Description toList() / toSet() List<T> / Set<T> Accumulates into a List or Set toCollection(Supplier) Specific Collection E.g. toCollection(TreeSet::new) toMap(keyMapper, valMapper) Map<K, V> Collects into key-value map joining(delimiter, prefix, suffix) String Concatenates CharSequences groupingBy(classifier) Map<K, List<T>> Groups elements by key category groupingBy(classifier, downstream) Map<K, D> Groups by key and applies downstream reduction partitioningBy(predicate) Map<Boolean, List<T>> Splits into true and false buckets…
Key Takeaways
Collectors transforms stream results into lists, sets, maps, or aggregated metrics.
groupingBy acts like SQL GROUP BY, supporting nested downstream collectors.
partitioningBy splits elements into a Map<Boolean, List<T>> based on a predicate.
summarizingDouble provides min, max, sum, average, and count in a single pass.
toMap handles key collisions using an explicit merge binary operator.