In the tutorial Java Stream Collectors averagingInt(), averagingLong(), averagingDouble() we saw how Collectors class in Java Stream API provides methods like Collectors.averagingInt(), Collectors.averagingLong(), Collectors.averagingDouble() to get average of Stream on Integers, Long and Double respectively. Same way if you want to quickly add the stream elements there are Collectors.summing() methods which have the following forms for different types- summingInt(ToIntFunction<? super T> mapper) - To get sum of stream of integers. If no elements are present, the result is 0. summingLong(ToLongFunction<? super T> mapper) - To get sum of stream of longs. If no elements are present, the result is 0. summingDouble(ToDoubleFunction<? super T> mapper) - To get sum of stream of doubles. If no elements are present, the result is 0. Argument passed to the methods is of type ToIntFunction, ToLongFunction and ToDoubleFunction respectively. These are functio
KnpCode
Java, Spring, Web development tutorials with examples