ArrayList forEach(Consumer super action) method in java code example
Example 1: ArrayList forEach(Consumer super action) method in java
import java.util.ArrayList;
public class ArrayListForEachMethodExample
{
public static void main(String[] args)
{
ArrayList<String> colors = new ArrayList<String>();
colors.add("red");
colors.add("blue");
colors.add("green");
colors.add("yellow");
System.out.println("list of colors: ");
// forEach method of ArrayList
colors.forEach((n) -> System.out.println(n));
}
}
Example 2: ArrayList forEach(Consumer super action) method in java
import java.util.ArrayList;
public class ArrayListForEachMethodExample
{
public static void main(String[] args)
{
ArrayList<Integer> al = new ArrayList<Integer>();
al.add(10);
al.add(50);
al.add(20);
al.add(82);
al.add(75);
// print numbers using forEach method of ArrayList
al.forEach((n) -> System.out.println(n));
}
}