// Hunter Schafer, CSE 143 // Class that shows off foreach loops import java.util.*; public class IterationExample { public static void main(String[] args) { List tas = new ArrayList(); tas.add("Kyle"); tas.add("Jin"); tas.add("Aaron"); tas.add("Ian"); tas.add("Miri"); tas.add("Ayaz"); tas.add("Zach"); System.out.println(tas); for (int i = 0; i < tas.size(); i++) { String ta = tas.get(i); System.out.println(ta); } // 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 which we will // talk about on Friday. for (String ta : tas) { // do what you want with ta System.out.println(ta); } } }