Close

Java 8 Streams - LongStream.mapToInt Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.LongStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.LongStreamLongStreamLogicBig

Method:

IntStream mapToInt(LongToIntFunction mapper)

This intermediate operation returns an IntStream consisting of the results of applying the given function to the elements of this stream.


Examples


package com.logicbig.example.longstream;

import java.util.stream.IntStream;
import java.util.stream.LongStream;

public class MapToIntExample {

public static void main(String... args) {
LongStream stream = LongStream.of(4, 7, 9, 11, 13, 17);
IntStream intStream = stream.mapToInt(Math::toIntExact);
intStream.forEach(System.out::println);
}
}

Output

4
7
9
11
13
17




See Also