Close

Java 8 Streams - DoubleStream.mapToObj Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.DoubleStream

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

Method:

<U> Stream<U> mapToObj(DoubleFunction<? extends U> mapper)

This intermediate operation returns an object-valued Stream consisting of the results of applying the given mapper function to the elements of this stream.

Examples


package com.logicbig.example.doublestream;

import java.math.BigDecimal;
import java.util.stream.DoubleStream;
import java.util.stream.Stream;

public class MapToObjExample {

public static void main(String... args) {
DoubleStream ds = DoubleStream.of(1.0, 1.2, 2.0, 2.4, 3.0);
Stream<BigDecimal> stream = ds.mapToObj(BigDecimal::valueOf);
stream.map(bd -> bd.multiply(BigDecimal.TEN))
.forEach(System.out::println);
}
}

Output

10.0
12.0
20.0
24.0
30.0




See Also