Reduction

Reduction combines all the elements of a stream into a single value. reduce(identity, accumulator) applies an associative operation, such as a sum; primitive streams (IntStream) offer sum, average, max. The identity is the neutral value, such as 0 for a sum.

Example

int total = Stream.of(1, 2, 3).reduce(0, Integer::sum); // 6

Related concepts

The whole glossary