Iterators
Objective
Iterators
- Enumeration
- first Iterator-style interface in Java
- only two methods: hasMoreElements() and nextElement()
- import java.util.Enumeration;
- see TestEnumeration1.java for sample implementation
- newer classes often use Iterator instead
- Iterator
- newer than Enumeration, but very similar
- three methods: hasNext(), next(), remove()
- import java.util.Iterator;
- see TestIterator1.java for sample usage
- ListIterator
- ListIterators are like Iterators, but with the abilty to
step forward AND backward
- new methods: hasPrevious(), previous()
- a handfull of other methods have been added: add, set,
nextIndex, previousIndex
- import java.util.ListIterator;
- see TestIterator2.java for sample usage