ListIterator<T>
Random access iterator for List. Supports forward, backward, and index-based traversal.
xxml
Language::CollectionsForward Iteration
| Method | Parameters | Returns | Description |
|---|---|---|---|
| hasNext | — | Bool^ | More elements ahead |
| next | — | T^ | Advance and return element |
| current | — | T^ | Current element (no advance) |
Backward Iteration
| Method | Parameters | Returns | Description |
|---|---|---|---|
| hasPrevious | — | Bool^ | More elements behind |
| previous | — | T^ | Move back and return element |
Random Access
| Method | Parameters | Returns | Description |
|---|---|---|---|
| advance | n: Integer^ | None | Move n positions forward |
| at | idx: Integer^ | T^ | Get element at absolute index |
| index | — | Integer^ | Current position |
Utility
| Method | Parameters | Returns | Description |
|---|---|---|---|
| reset | — | None | Return to beginning |
| toEnd | — | None | Move to end |
| equals | other: ListIterator<T>^ | Bool^ | Compare positions |
| distance | other: ListIterator<T>^ | Integer^ | Elements between iterators |
Examples
List Iteration
xxml
Instantiate Collections::List<Integer>^ As <nums> = Collections::List@Integer::Constructor();
Run nums.add(Integer::Constructor(10));
Run nums.add(Integer::Constructor(20));
Run nums.add(Integer::Constructor(30));
Instantiate Collections::ListIterator<Integer>^ As <iter> = nums.begin();
// Forward iteration
While (iter.hasNext()) -> {
Run Console::printLine(iter.next().toString());
}
// Output: 10, 20, 30