Stream flatMapToLong(Function mapper) applies given mapper function to each element of a stream and returns a LongStream. Stream flatMapToLong(Function mapper) is an intermediate operation. 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.
LongStream flatMapToLong(Function<? super T, ? extends LongStream> mapper) Where, LongStream is a sequence of primitive long-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 : flatMapToLong() with operation of parsing string to long.
1 2 3 4 5
Example 2 : flatMapToLong() with operation of mapping string with string length.
5 3 13 3
Example 3 : flatMapToLong() function with operation of returning stream.
Exception in thread "main" java.lang.NumberFormatException: For input string: "5.36"
Note : A Java NumberFormatException usually occurs when you try to do something like converting a String to a numeric value, like an int, float, double, long etc.
- Stream map() in Java with examples
- Stream.of(T t) in Java with examples
- Stream flatMapToInt() in Java with examples
- Stream flatMapToDouble() in Java with examples
- Stream.of(T... values) in Java with examples
- Stream builder() in Java with Examples
- Stream empty() in Java with Examples
- Stream mapToLong() in Java with examples
- Stream peek() in Java with examples
- Stream mapToInt() in Java with examples
- Stream mapToDouble() in Java with examples
- Java Stream findAny() with examples
- Stream findFirst() in Java with examples
- Stream flatMap() in Java with examples
- Stream filter() in Java with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.