DoubleStream peek() is a method in java.util.stream.DoubleStream. The function returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed from the resulting stream.
DoubleStream peek() is an intermediate operation. These operations are always lazy. Intermediate operations are invoked on a Stream instance and after they finish their processing, they give a Stream instance as output.
DoubleStream peek(DoubleConsumer action)
- DoubleStream : A sequence of primitive double-valued elements.
- DoubleConsumer : Represents an operation that accepts a single double-valued argument and returns no result.
Return Value : the function returns a parallel DoubleStream.
Note : This method exists mainly to support debugging.
Example 1 : Performing sum operation to find sum of elements of given DoubleStream.
2.2 3.3 4.5 6.7 sum is : 16.7
Example 2 : Performing count operation on elements of given DoubleStream.
2.2 3.3 4.5 6.7 count : 4
Example 3 : Performing average operation on elements of given DoubleStream.
2.2 3.3 4.5 6.7 Average is : 4.175
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.