This terminal operation returns an OptionalDouble describing the arithmetic mean of elements of this stream, or an empty optional if this stream is empty. This is a special case of reduction.
Examples
Using LongStream#average method:
package com.logicbig.example;
import java.util.stream.LongStream;
public class AverageExample { public static void main (String[] args) { double v = LongStream.range(1, 10).average().orElse(-1); System.out.println(v); } }