DoubleStream peek() in Java with examples
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
Please Login to comment...