java 8 stream forEach method example

The java.util.stream is a sequence of elements supporting sequential and parallel aggregate operations.
The Stream.forEach() method works same as of for loop. It iterates through each element and performs the specified operations.

Java 8 stream forEach method example

package com.w3spoint;
 
import java.util.Arrays;
import java.util.List;
 
public class Test{  
    public static void main(String[] args) {  
    	List<String> names = Arrays.asList("jai", "hemant", "mahesh", "vishal", "vivek");
        names.stream().forEach(System.out::println);
    }  
}

Output

jai
hemant
mahesh
vishal
vivek
Please Share