IntStream toArray() example

Description

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

Syntax

toArray has the following syntax.


int[] toArray()

Example

The following example shows how to use toArray.


import java.util.stream.IntStream;
/*  w  ww . j av  a 2s.c  o m*/
public class Main {
  public static void main(String[] args) {
    IntStream i = IntStream.of(6,5,7,1, 2, 3, 3);
    int[] v = i.toArray();
    for(int n:v){
      System.out.println(n);  
    }
  }
}

The code above generates the following result.





















Home »
  Java Streams »
    Reference »




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