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.w3schools; import java.util.Arrays; import java.util.List; public class Test{ public static void main(String[] args) { Listnames = Arrays.asList("jai", "hemant", "mahesh", "vishal", "vivek"); names.stream().forEach(System.out::println); } }
Output
jai hemant mahesh vishal vivek