Close

Java 8 Streams - LongStream.mapToDouble Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.LongStream

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

Method:

DoubleStream mapToDouble(LongToDoubleFunction mapper)

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

Examples


package com.logicbig.example.longstream;

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

public class MapToDoubleExample {

public static void main(String... args) {
LongStream stream = LongStream.of(4, 7, 9, 11, 13, 17);
DoubleStream doubleStream = stream.mapToDouble(MapToDoubleExample::half);
doubleStream.forEach(System.out::println);
}

private static double half(long operand) {
return operand / 2d;
}
}

Output

2.0
3.5
4.5
5.5
6.5
8.5




See Also