How do you find the sum of list elements using Java streams?

Summing elements in a stream of integers is done by converting to an IntStream with mapToInt, then calling its sum() terminal operation.

Key Points

Example

Given the list [1, 2, 3, 4, 5], converting to an IntStream and calling sum() produces 15.

int sum = numbers.stream()
        .mapToInt(Integer::intValue)
        .sum();

Interview Tip

A concise interview answer is

I convert the boxed stream to a primitive IntStream with mapToInt(Integer::intValue), then call sum(), which avoids the boxing overhead of using reduce(0, Integer::sum) directly on a Stream<Integer> and gives access to other numeric aggregates like average() and max().

Last updated: 11 November 2026

Previous question: How do you find the maximum value in a list using Java streams?

Next question: How do you convert a list of names to uppercase using Java streams?

More Stream API Coding Questions - Level I interview questions

All Stream API Coding Questions - Level I questions