arraylist foreach 28consumer super action 29 method in java

Solutions on MaxInterview for arraylist foreach 28consumer super action 29 method in java by the best coders in the world

showing results for - "arraylist foreach 28consumer super action 29 method in java"
Emilia
28 Feb 2016
1import java.util.ArrayList;
2public class ArrayListForEachMethodExample
3{
4   public static void main(String[] args)
5   {
6      ArrayList<Integer> al = new ArrayList<Integer>();
7      al.add(10);
8      al.add(50);
9      al.add(20);
10      al.add(82);
11      al.add(75);
12      // print numbers using forEach method of ArrayList
13      al.forEach((n) -> System.out.println(n));
14   }
15}
Dina
27 Oct 2017
1import java.util.ArrayList;
2public class ArrayListForEachMethodExample
3{
4   public static void main(String[] args)
5   {
6      ArrayList<String> colors = new ArrayList<String>();
7      colors.add("red");
8      colors.add("blue");
9      colors.add("green");
10      colors.add("yellow");
11      System.out.println("list of colors: ");
12      // forEach method of ArrayList
13      colors.forEach((n) -> System.out.println(n));
14   }
15}