/************************************************** * Author: Morrison * Date: 22 Apr 2021 **************************************************/ import java.util.ArrayList; public class Collect { public static void main(String[] args) { ArrayList x = new ArrayList<>(); x.add("aardvark"); x.add("bobcat"); x.add("cheetah"); x.add("dingo"); x.add("eland"); x.add("ferret"); //for (type iter: collection){} for(String k : x) // this is a "foreach" loop. { System.out.println(k); } //write a loop that totals the number of characters //in the list x. int 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(); } } }