Skip to main content
ICT
Lesson A15 - ArrayList
 
Main   Previous Next
 

E. Iterator page 7 of 11

An Iterator is an object that is attached to the ArrayList and allows you to traverse the array from first to last element. Many data structures implement an Iterator. The Iterator keeps track of where it is in the list even if we are adding and removing from it. We will cover the topic of Iterators much more thoroughly in the AB level curriculum.

ArrayList<String> names = new ArrayList<String>();
names.add(“George”);
names.add(“Nancy”);
names.add(“John”);

Iterator iter = names.iterator();
while(iter.hasNext())
{
     System.out.println(iter.next());
}

 

Main   Previous Next
Contact
 © ICT 2006, All Rights Reserved.