Stream flatMapToDouble(Function mapper) returns an DoubleStream consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element. Stream flatMapToDouble(Function 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.
Note : Each mapped stream is closed after its contents have been placed into this stream. If a mapped stream is null, an empty stream is used, instead.
DoubleStream flatMapToDouble(Function<? super T, ? extends DoubleStream> mapper) Where, DoubleStream is 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 : flatMapToDouble() function with operation of parsing string to double.
1.5 2.7 3.0 4.0 5.6
Example 2 : flatMapToDouble() function with operation of returning stream with length of strings.
5.0 3.0 13.0 3.0
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.