Java Stream How to - Convert List to Stream








Question

We would like to know how to convert List to Stream.

Answer

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
/* w  w w.j  a v  a 2s  . c  om*/
public class Main {
   public static void main(String[] args) {
     List<Integer> numberList = Arrays.asList(1, 2, 3, 4, 5);
     Stream<Integer> listStream = numberList.stream();

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

}

The code above generates the following result.