Collector, as of Java 8, is a mutating reduction operation on a Stream. Use this tag for specific questions about the usage of Collectors.
Collector
, as of Java 8, is an interface representing a mutating reduction operation on Stream
, defined in the documentation as
A mutable reduction operation that accumulates input elements into a mutable result container, optionally transforming the accumulated result into a final representation after all input elements have been processed.
Sample usage:
The Collectors
utility class provides several built-in methods to obtain instances of Collector
:
- To collect a
Stream
into aList
, useCollectors.toList
. - To collect a
Stream
into aSet
, useCollectors.toSet
. - To collect a
Stream
into aMap
, useCollectors.toMap
.