CodesJava

Easy learning with example program codes

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.codesjava;
 
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


Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap