Iterator
ListIterator iterates over lists, that are instances of classes that
implement the List interface.
An iterator is quite simple to use. There is one method to check whether there are more elements left to iterate over hasNext, one method to get the next element next and one to remove the current element remove.
Example:
var list:List = new MyList();
list.insert("value1");
list.insert("value2");
list.insert("value3");
var iterator:Iterator = new ListIterator(list);
while (iterator.hasNext()) {
trace(iterator.next());
}
Output:
value1 value2 value3
public function ListIterator(target:List)
Constructs a new ListIterator instance.
target | the list to iterate over |
public function hasNext(Void):BooleanReturns whether there is another element to iterate over.
true if there is at least one element left to iterate
over
public function next(Void)Returns the next element.
the next element
| NoSuchElementException | if there is no next element |
public function remove(Void):VoidRemoves the currently selected element from this iterator and from the data holder this iterator iterates over.
| IllegalStateException | if you try to remove an element when none is selected |