Close

Java 8 Streams - DoubleStream.mapToLong Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.DoubleStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.DoubleStreamDoubleStreamLogicBig

Method:

LongStream mapToLong(DoubleToLongFunction 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.doublestream;

import java.util.stream.DoubleStream;
import java.util.stream.LongStream;

public class MapToLongExample {

public static void main(String... args) {
DoubleStream ds = DoubleStream.of(1.0, 1.2, 2.0, 2.4, 3.0);
LongStream ls = ds.mapToLong(Math::round);
ls.forEach(System.out::println);
}
}

Output

1
1
2
2
3




See Also