DoubleStream mapToObj(DoubleFunction mapper) example

Description

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;
/*from ww  w  .jav  a 2  s. c o  m*/
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.





















Home »
  Java Streams »
    Reference »




Collectors
DoubleStream
DoubleStream.Builder
IntStream
IntStream.Builder
LongStream
LongStream.Builder
Stream
Stream.Builder