The Iterator Pattern
An Introduction with Examples in Java |
Prof. David Bernstein |
Computer Science Department |
bernstdh@jmu.edu |
HashSet
instead of an
ArrayList
? Iterable<String> cities; cities = new ArrayList<String>(); // Important code // An example loop Iterator<String> i = cities.iterator(); while (i.hasNext()) { String city = i.next(); System.out.println(city); }
Object
that implements the Iterable
interface)Iterable<String> cities; cities = new ArrayList<String>(); // Important code // An example loop for (String city: cities) { System.out.println(city); }