Java: Numeric summary with summarizingInt

summarizingInt computes count, sum, min, average and max in a single pass.

Code
IntSummaryStatistics stats = Stream.of(4, 8, 15, 16, 23, 42)
        .collect(Collectors.summarizingInt(Integer::intValue));
System.out.printf("count=%d min=%d max=%d avg=%.1f%n",
        stats.getCount(), stats.getMin(), stats.getMax(), stats.getAverage());
Output
count=6 min=4 max=42 avg=18.0
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-07-26