Java, forEach is a method introduced in Java 8 in the Iterable interface. It's a part of the Stream API and provides a way to iterate over elements of a collection and perform an action on each element. It takes a functional interface as an argument, typically a lambda expression or a method reference, which represents the action to be performed on each element. Here's the syntax of forEach method: void forEach (Consumer<? super T> action) Where: action is the action to be performed for each element. Consumer is a functional interface from the java.util.function package. It represents an operation that accepts a single input argument and returns no result. Let's see some examples: Example 1: Basic usage with ArrayList import java.util.ArrayList; public class ForEachExample { public static void main (String[] args) { ArrayList<String> names = ArrayList<String> names = new ArrayList <>(); names.add( ...