collector

A recipe passed to a stream's collect operation that gathers the elements into a result, such as a set or a map grouped by key.

In more detail

The Collectors class supplies common ones: toSet collects unique values, groupingBy builds a map from a key to the values that share it, and joining builds a string. Prefer the collector that states your intended result directly.

Example

.collect(Collectors.groupingBy(Order::status))

Related terms

Taught in

References

Certification courses