IntStream flatMap(IntFunction mapper) returns a stream 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. This 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 flatMap(IntFunction<? extends IntStream> mapper)
- IntStream : A sequence of primitive int-valued elements.
- IntFunction : A function that accepts an int-valued argument and produces a result.
- mapper : A stateless function which is applied to each element and the function returns the new stream.
Return Value : IntStream flatMap(IntFunction mapper) returns a stream by a mapped stream using mapping function.
Example 1 : Using IntStream flatMap() to get the cube of elements of IntStream.
64 125 216 343
Example 2 :Using IntStream flatMap() to get the count of set bits in binary representation of elements of IntStream.
3 1 3 3
- IntStream map(IntUnaryOperator mapper) in Java
- DoubleStream flatMap(DoubleFunction mapper) in Java
- DoubleStream map(DoubleUnaryOperator mapper) in Java
- LongStream flatMap(LongFunction mapper) in Java
- LongStream map(LongUnaryOperator mapper) in Java
- Java | Collectors averagingLong (ToLongFunction mapper) with Examples
- java.util.stream.IntStream/LongStream | Search an element
- IntStream iterator() in Java
- IntStream rangeClosed() in Java
- IntStream findFirst() in Java
- IntStream parallel() in Java
- IntStream empty() in Java with examples
- IntStream distinct() in Java with examples
- IntStream peek() in Java with examples
- IntStream average() in Java with Examples
- IntStream max() in Java with examples
- IntStream min() in Java with Examples
- IntStream count() in Java with examples
- IntStream skip() in Java
- IntStream 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 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.