How do you use reduce() to sum a list in Java streams?

reduce() is a general-purpose terminal Stream operation that combines all elements into a single result using an identity value and an accumulator function.

Key Points

Example

Given the list [1, 2, 3, 4], calling reduce(0, Integer::sum) folds the elements together starting from 0, producing a total of 10.

int total = numbers.stream()
        .reduce(0, Integer::sum);

Interview Tip

A concise interview answer is

reduce(identity, accumulator) folds a stream down to a single value, starting from the identity and combining elements one at a time with the accumulator function. For summing integers, reduce(0, Integer::sum) is equivalent to using an IntStream's sum(), just more general-purpose.

Last updated: 11 November 2026

Previous question: How do you get distinct elements from a list using Java streams?

Next question: How does findAny() work in Java streams?

More Stream API Coding Questions - Level I interview questions

All Stream API Coding Questions - Level I questions