Java Stream How to - Convert array to Stream with Arrays








Question

We would like to know how to convert array to Stream with Arrays.

Answer

import java.util.Arrays;
import java.util.stream.Stream;
//  w w w  . java  2 s  .c  om
public class Main {
   public static void main(String[] args) {
     Integer[] numbers = {1, 2, 3, 4};
     Stream<Integer> arrayStreams2 = Arrays.stream(numbers);

     System.out.println(Arrays.toString(arrayStreams2.toArray()));
   }

}

The code above generates the following result.