Finding Statistics about Numerical Streams

suggest change

Java 8 provides classes called IntSummaryStatistics, DoubleSummaryStatistics and LongSummaryStatistics which give a state object for collecting statistics such as count, min, max, sum, and average.

List<Integer> naturalNumbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
IntSummaryStatistics stats =
                                           .mapToInt((x) -> x)

Which will result in:

IntSummaryStatistics{count=10, sum=55, min=1, max=10, average=5.500000}

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents