java 8 create stream example

The java.util.stream is a sequence of elements supporting sequential and parallel aggregate operations.

Java 8 create stream example

package com.w3spoint;
 
import java.util.stream.Stream;
 
public class Test{  
    public static void main(String[] args) {  
    	//Create Stream using Stream.of
        Stream<String> names = Stream.of("Jai","Hemant");
        names.forEach(System.out::println);
 
        System.out.println("--------------");
        //Create stream using array of elements
        Stream<Integer> intStream1 = Stream.of(new Integer[]{1,2,3,4,5});
        intStream1.forEach(System.out::println);
    }  
}

Output

Jai
Hemant
--------------
1
2
3
4
5
Content Protection by DMCA.com
Please Share