//A Stream of Integers
var ints = Stream.of(10, 20, 30 , 40);

//Calculate the average using the Collectors.teeing method.
long average = ints.collect(
        Collectors.teeing(
                
                //Sum all of the integers in the stream.
                Collectors.summingInt(Integer::valueOf),
                
                //Count the content of the stream.
                Collectors.counting(),
                
                //Calculate the average.
                ( sum, count) -> sum / count
        )
);

System.out.println(average);