LongStream average() in Java with Examples
java.util.stream.LongStream in Java 8, deals with primitive Longs. It helps to solve the old problems like finding maximum value in array, finding minimum value in array, sum of all elements in array, and average of all values in array in a new way. LongStream average() returns an OptionalDouble describing the arithmetic mean of elements of this stream, or an empty optional if this stream is empty.
OptionalDouble average() Where, OptionalDouble is a container object which may or may not contain a double value.
Below given are some examples to understand the function in a better way.
Example 1 :
Example 2 :