Java Streams - DoubleStream toArray() example








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 w  w.  j  a  v  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);
    
    double[] array = b.toArray();
    for(double d:array){
      System.out.println(d);
    }
  }
}

The code above generates the following result.