The collection interface in JAVA8 is extended to provide two ways to get the stream:
Default Stream<e> Stream (): Returns a sequential stream
Default Stream<e> parallelstream (): Returns a parallel stream
1 Create
1. Collection provides two methods for stream () and Parallelstream ()
New Arraylist<>(); Stream// get a sequential stream // get a parallel stream
2. Get an array stream through stream () in Arrays
New Integer[10]; Stream<Integer> stream1 = Arrays.stream (nums);
3 static method by Stream class of ()
stream<integer> stream2 = Stream.of (1,2,3,4,5,6);
4 Creating an infinite stream
// Iteration stream<integer> stream3 = stream.iterate (0, (x), X + 2). Limit (n); Stream3.foreach (System.out::p rintln);
5
// Build stream<double> stream4 = stream.generate (math::random). Limit (2); Stream4.foreach (System.out::p rintln);
Java8 new Features-stream