How do you get summary statistics (count, sum, min, average, max) using Java streams?

summaryStatistics() is a terminal operation on a primitive stream (IntStream, LongStream, DoubleStream) that computes count, sum, min, max, and average in a single pass.

Key Points

Example

Given a list of order totals, calling summaryStatistics() lets you print the total revenue, the average order size, and the largest order in a single line instead of three separate stream passes.

IntSummaryStatistics stats = numbers.stream()
        .mapToInt(Integer::intValue)
        .summaryStatistics();

System.out.println(stats.getMax() + " " + stats.getAverage());

Interview Tip

A concise interview answer is

summaryStatistics() on an IntStream gives me count, sum, min, max, and average from a single pass over the data, via the returned IntSummaryStatistics object. It's more efficient than chaining separate sum(), max(), and average() calls when I need several aggregates at once.

Last updated: 11 November 2026

Previous question: How do you convert a stream to a Set in Java?

More Stream API Coding Questions - Level I interview questions

All Stream API Coding Questions - Level I questions