Stream mapToInt(ToIntFunction mapper) returns an IntStream consisting of the results of applying the given function to the elements of this stream.
Stream mapToInt(ToIntFunction 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.
IntStream mapToInt(ToIntFunction<? super T> 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 : mapToInt() with operation of printing the stream element if divisible by 3.
3 6 15
Example 2 : mapToInt() to return IntStream after performing operation of mapping string with its length.
5 3 3 13 9
- LongStream mapToInt() in Java with Examples
- DoubleStream mapToInt() in Java
- Stream map() in Java with examples
- Stream.of(T t) in Java with examples
- Stream flatMap() in Java with examples
- Stream flatMapToInt() in Java with examples
- Java Stream findAny() with examples
- Stream.reduce() in Java with examples
- Stream.of(T... values) in Java with examples
- Stream flatMapToDouble() in Java with examples
- Stream mapToDouble() in Java with examples
- Stream min() method in Java with Examples
- Stream.max() method in Java with Examples
- Stream flatMapToLong() in Java with examples
- Stream builder() 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.