DoubleStream toArray() example

Description

DoubleStream toArray() returns an array containing the elements of this stream. This is a terminal operation.

Syntax

toArray has the following syntax.


double[] toArray()

Example

The following example shows how to use toArray.


import java.util.stream.DoubleStream;
//from  w  ww.  j  av a  2  s . co m
public class Main {
  public static void main(String[] args) {
    DoubleStream b = DoubleStream.of(1.1,2.2,3.3,4.4,5.5);
    
    double[] array = b.toArray();
    for(double d:array){
      System.out.println(d);
    }
  }
}

The code above generates the following result.





















Home »
  Java Streams »
    Reference »




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