// Erika Wolfe, CSE 143 // Class that shows off foreach loops import java.util.*; public class ForEachLoop { public static void main(String[] args) { List tas = new ArrayList(); tas.add("Shanti"); tas.add("Melissa"); tas.add("Josh"); tas.add("Jason"); tas.add("Suzanne"); tas.add("Isaac"); tas.add("BEN"); System.out.println(tas); for (int i = 0; i < tas.size(); i++) { System.out.println(tas.get(i)); } System.out.println(); // This is basically the same loop but instead of specifying // the indices and making a variable inside the loop, // you just say a variable name and Java will change the variable // on each iteration of the loop. The order of the foreach loop // depends on "iteration order" of the collection. for (String ta : tas) { System.out.println(ta); } } }