import java.util.ArrayList; public class PrintList { public static void main(String[] args) { ArrayList x = new ArrayList<>(); x.add("avocado"); x.add("banana"); x.add("clementine"); x.add("dhurrian"); // python uses for k in x: // Collections for loop for(String k : x) { System.out.println(k); } //instant puzzler: compute the number of //characters in the list's strings. //print the result. int total = x.stream() .mapToInt(String::length) .sum(); System.out.printf("total = %s\n", total); total = 0; for(String k:x) { total += k.length(); } System.out.printf("total = %s\n", total); total = 0; for(int k = 0; k < x.size(); k++) { total += x.get(k).length(); } System.out.printf("total = %s\n", total); } }