Stream flatMapToInt(Function mapper) returns an IntStream 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 flatMapToInt(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.
IntStream flatMapToInt(Function<? super T, ? extends IntStream> mapper) Where, IntStream is a sequence of primitive int-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 : flatMapToInt() function with operation of parsing string to Integer.
1 2 3 4 5
Example 2 : flatMapToInt() function with operation of mapping string with their length.
5 3 13 3
- Stream.of(T t) in Java with examples
- Stream map() in Java with examples
- Stream anyMatch() in Java with examples
- Java Stream findAny() with examples
- Stream findFirst() in Java with examples
- Stream flatMap() in Java with examples
- Stream flatMapToDouble() in Java with examples
- Stream flatMapToLong() in Java with examples
- Stream filter() in Java with examples
- Stream allMatch() in Java with examples
- Stream toArray() in Java with Examples
- Stream empty() in Java with Examples
- Stream builder() in Java with Examples
- Stream min() method in Java with Examples
- Stream.of(T... values) 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 firstname.lastname@example.org. 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.