Close

Java 8 Streams - LongStream.mapToObj Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.LongStream

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

Method:

<U> Stream<U> mapToObj(LongFunction<? 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.longstream;

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

public class MapToObjExample {

public static void main(String... args) {
LongStream stream = LongStream.of(4, 7, 9, 11, 13, 17);
Stream<BigDecimal> stream2 = stream.mapToObj(BigDecimal::new);
stream2.forEach(bd -> System.out.println(bd.divide(BigDecimal.TEN)));
}
}

Output

0.4
0.7
0.9
1.1
1.3
1.7




See Also