javascript-collections-framework
    Preparing search index...

    Interface ListCursor<E>

    A cursor over a list that moves both ways and edits at its position. It sits between two elements: next() returns the element after it, previous() the element before it.

    const cursor = list.listCursor()
    while (cursor.hasNext()) {
    const n = cursor.next()
    if (n < 0) cursor.remove()
    else if (n === 0) cursor.insert(-1)
    else cursor.set(n * 2)
    }
    interface ListCursor<E> {
        hasNext(): boolean;
        hasPrevious(): boolean;
        insert(element: E): void;
        next(): E;
        nextIndex(): number;
        previous(): E;
        previousIndex(): number;
        remove(): void;
        set(element: E): void;
    }

    Type Parameters

    • E

    Hierarchy (View Summary)

    Index
    • Returns whether next() has an element to return. Never throws. Time: O(1) unless the collection documents otherwise.

      Returns boolean

    • Returns whether previous() has an element to return. Never throws. Time: O(1).

      Returns boolean

    • Inserts element just before the cursor: a following next() is unaffected and a following previous() returns element.

      Time: as the list's insert at this position.

      Parameters

      • element: E

        The element to insert.

      Returns void

      UnsupportedOperationError when the list cannot be changed.

      ConcurrentModificationError when the list was changed other than through this cursor.

    • Returns the next element.

      Time: O(1) unless the collection documents otherwise.

      Returns E

      The next element.

      NoSuchElementError when no element remains.

      ConcurrentModificationError when a fail-fast collection was changed other than through this cursor.

    • Returns the index of the element next() would return, or size at the end. Never throws. Time: O(1).

      Returns number

    • Returns the element before the cursor and moves the cursor back past it.

      Time: O(1).

      Returns E

      The previous element.

      NoSuchElementError when the cursor is at the start.

      ConcurrentModificationError when the list was changed other than through this cursor.

    • Returns the index of the element previous() would return, or -1 at the start. Never throws. Time: O(1).

      Returns number

    • Removes the element the last next() returned.

      Time: as the implementation documents.

      Returns void

      IllegalStateError when called before next(), or twice without a next() between (on a list cursor, previous() counts as a move too).

      UnsupportedOperationError when the collection cannot be changed (a read-only view).

      ConcurrentModificationError when a fail-fast collection was changed other than through this cursor.

    • Replaces the element the last next() or previous() returned. Open iterators and other cursors stay valid.

      Time: O(1).

      Parameters

      • element: E

        The new element.

      Returns void

      IllegalStateError when there was no next()/previous(), or an insert or remove since.

      UnsupportedOperationError when the list cannot be changed.

      ConcurrentModificationError when the list was changed other than through this cursor.