Close

Java 8 Streams - IntStream.mapToLong Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.IntStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.IntStreamIntStreamLogicBig

Method:

LongStream mapToLong(IntToLongFunction mapper)

This intermediate operation returns a LongStream consisting of the results of applying the given mapper function to the elements of this stream.

Examples


package com.logicbig.example.intstream;

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

public class MapToLongExample {

public static void main(String... args) {
IntStream intStream = IntStream.range(1, 5);
LongStream mapToLong = intStream.mapToLong(i -> (long) i + Integer.MAX_VALUE);
mapToLong.forEach(System.out::println);
}
}

Output

2147483648
2147483649
2147483650
2147483651




See Also