import java.util.ArrayList; public class ListPrinting { public static void main(String[] args) { ArrayList<String> zoo = new ArrayList<>(); zoo.add("antelope"); zoo.add("badger"); zoo.add("carical"); zoo.add("dingo"); zoo.add("elephant"); zoo.add("fox"); sizeMe(zoo); } public static void printWhile(ArrayList<String> zoo) { int index = 0; while(index < zoo.size()) { System.out.println(zoo.get(index)); index++; } } public static void printFor(ArrayList<String> zoo) { //This is the C for loop //for(init; test; between){} for(int index = 0; index < zoo.size(); index++) { System.out.println(zoo.get(index)); } } public static void printForCollection(ArrayList<String> zoo) { //This is the C for loop //collections for loop for(String item: zoo) { System.out.println(item); } } public static void printForEach(ArrayList<String> zoo) { //This is the C for loop //collections for loop zoo.forEach(System.out::println); // This is a method reference. We are treating thew // method System.out.println as a function OBJECT. } public static void sizeMe(ArrayList<String> zoo) { //argument is a lambda, an anonymous function. zoo.forEach( str -> System.out.println(str.length())); } }