package blatt13; import java.util.Iterator; import java.util.LinkedList; import java.util.List; public class IteratorTest { public static void main(String[] args) { List list = new LinkedList<>(); // Befüllen: for (int i = 0; i < 20; i++) { list.add(i); } // Beispiele 1 und 2: if (false) { Iterator it = list.iterator(); while (true) { // Beispiel 1 System.out.println(it.next()); // a.add(7); // Beispiel 2 } } // Beispiel 3: else if (false) { Iterator it2 = list.iterator(); list.add(21); // möglich? if (false) { System.out.println(it2.next()); } } // Beispiel 4: else if (false) { System.out.println(list); //return; int i = 0; for (int tmp : list) { System.out.print(tmp + " "); i++; if (i > 18) { list.remove(0); } } System.out.println(); System.out.println(list); } // Beispiel 5 (SymmetricStack): else if (false) { SymmetricStack stack = new SymmetricStack(); for (int i = 0; i < 20; i++) stack.append(i); for (Integer i : stack) System.out.print(i + " "); System.out.println("\nDone."); Iterator it = stack.iterator(); while (it.hasNext()) { stack.prepend(42); System.out.print(it.next() + " "); } System.out.println("\nDone."); } } }