ListIterator<T>

Random access iterator for List. Supports forward, backward, and index-based traversal.

xxml
Language::Collections

Forward Iteration

MethodParametersReturnsDescription
hasNextBool^More elements ahead
nextT^Advance and return element
currentT^Current element (no advance)

Backward Iteration

MethodParametersReturnsDescription
hasPreviousBool^More elements behind
previousT^Move back and return element

Random Access

MethodParametersReturnsDescription
advancen: Integer^NoneMove n positions forward
atidx: Integer^T^Get element at absolute index
indexInteger^Current position

Utility

MethodParametersReturnsDescription
resetNoneReturn to beginning
toEndNoneMove to end
equalsother: ListIterator<T>^Bool^Compare positions
distanceother: 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

See Also