reduce

A terminal stream operation that combines all elements into one value, such as a sum, using a starting value and a combining operation.

In more detail

Built-in reductions such as sum and count cover common cases. A complicated custom reduction can hide business rules, so a named method or plain loop is often clearer.

Example

.reduce(0, Integer::sum)

Related terms

Taught in

References

Certification courses