Stream mapToDouble() in Java with examples
Stream mapToDouble (ToDoubleFunction mapper) returns a DoubleStream consisting of the results of applying the given function to the elements of this stream.
Stream mapToDouble (ToDoubleFunction mapper) 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 mapToDouble(ToDoubleFunction<? super T> mapper) Where, A sequence of primitive double-valued elements and T is the type of stream elements. mapper is a stateless function which is applied to each element and the function returns the new stream.
Example 1 : mapToDouble() with operation of selecting elements satisfying given function.
Example 2 : mapToDouble() with operation of returning a stream with square of string length.
9.0 16.0 9.0 9.0 1.0