Close

Java 8 Streams - IntStream.mapToDouble Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.IntStream

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

Method:

DoubleStream mapToDouble(IntToDoubleFunction 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.intstream;

import java.util.stream.DoubleStream;
import java.util.stream.IntStream;

public class MapToDoubleExample {

public static void main(String... args) {
IntStream intStream = IntStream.range(1, 5);
DoubleStream doubleStream = intStream.mapToDouble(i -> i / 2d);
doubleStream.forEach(System.out::println);
}
}

Output

0.5
1.0
1.5
2.0




See Also