This terminal operation returns an array containing the elements of this stream.
package com.logicbig.example.intstream;
import java.util.Arrays;
import java.util.stream.IntStream;
public class ToArrayExample {
public static void main(String... args) {
IntStream stream = IntStream.range(0, 10);
int[] ints = stream.toArray();
System.out.println(Arrays.toString(ints));
}
}
Output
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]