IntSummaryStatistics gathers count, sum, min, average and max together instead of running several terminal operations over the same data.
var latencies = List.of(120, 95, 310, 45, 180);
IntSummaryStatistics stats = latencies.stream()
.collect(Collectors.summarizingInt(Integer::intValue));
System.out.println("count = " + stats.getCount());
System.out.println("sum = " + stats.getSum());
System.out.println("min = " + stats.getMin());
System.out.println("average = " + stats.getAverage());
System.out.println("max = " + stats.getMax());
count = 5
sum = 750
min = 45
average = 150.0
max = 310
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-30