Summary statistics on a Java 8 stream of numbers
Java 8 streams provide an easy way to calculate basic statistics on the values of a stream of numbers. We can use the summaryStatistics method to get the basic statistics: minimum, maximum, count, sum and average.
List numbers = Arrays.asList(10, 3, 2, 5, 9, 4);
IntSummaryStatistics stats = numbers.