To produce an iterator from a vector, you define an Iterator
variable, then establish a value for that variable using the
iterator
method with the vector as the target. For example, to
produce an iterator named i
from the vector assigned to
mainVector
, you write the following expression:
Iterator i = mainVector.iterator()
Once you have created an iterator, you can fetch the successive elements from the
vector using the next
predicate:
i.next()
Thus, an iterator maintains a pointer to a place in the parent vector. When
you call next
, the iterator returns the element to the right of the
pointer and advances the pointer to the next element.