IndexTrackingIterator

A generic iterator that tracks the index of the current element.

This iterator wraps a standard ListIterator and maintains the index of the most recently read element, which can be accessed via currentIndex.

This class provides a generic implementation that can be used with any type of list elements. It correctly handles bidirectional iteration by tracking the current index internally.

This iterator is particularly useful for operations that need to know the position of elements during iteration, such as calculating correspondences between lists or tracking modifications.

Since

3.28.0

Parameters

<T>

the type of elements in the list

Constructors

Link copied to clipboard
constructor(elements: List<T>)
Creates an iterator starting at the beginning of the list.
constructor(elements: List<T>, fromIndex: Int)
Creates an iterator starting at the specified index.

Functions

Link copied to clipboard
open fun add(element: T)
Link copied to clipboard
open fun currentIndex(): Int
Returns the index of the element that was returned by the most recent call to next or previous.
Link copied to clipboard
open fun forEachRemaining(action: Consumer<in E>)
Link copied to clipboard
open fun hasNext(): Boolean
Link copied to clipboard
open fun hasPrevious(): Boolean
Link copied to clipboard
open fun next(): T
Link copied to clipboard
open fun nextIndex(): Int
Link copied to clipboard
open fun previous(): T
Link copied to clipboard
open fun previousIndex(): Int
Link copied to clipboard
open fun remove()
Link copied to clipboard
open fun set(element: T)