Java Streams - DoubleStream mapToObj(DoubleFunction mapper) example








DoubleStream mapToObj(DoubleFunction<? extends U> mapper) returns an object-valued Stream by applying the function to this stream. This is an intermediate operation.

Syntax

mapToObj has the following syntax.

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

Example

The following example shows how to use mapToObj.

import java.util.stream.DoubleStream;

public class Main {
  public static void main(String[] args) {
    DoubleStream b = DoubleStream.of(1.1,2.2,3.3,4.4,5.5);
    b.mapToObj(n -> {return n*n+"";})
     .forEach(System.out::println);
  }
}

The code above generates the following result.