How can I use Java 8 streams to calculate an average of the stream elements? Because I cannot use a stream twice I have to do it in one iteration. The stream contains custom beans holding a float value. The number of elements in the stream may vary. Hence, I want to sum up the float value of all elements in the stream and divide it by the number of elements in the stream.
Update: Finally I need the sum of all elements in the stream as well a the average of all elemnts of the stream.