Skip to content
Buy me a coffee

Vector

Defined in: src/list/Vector.ts:27

Legacy growable array list: an ArrayList plus the old element-style methods (elementAt, addElement, elements(), …), a reported capacity() with capacityIncrement, and ArrayIndexOutOfBoundsException for bad indexes. It is meant for porting code that uses them; new code should use ArrayList.

Complexity, null policy (null and undefined allowed) and index-order iteration are those of ArrayList. JS is single-threaded, so there is no synchronization.

E

new Vector<E>(): Vector<E>

Defined in: src/list/Vector.ts:34

Creates an empty vector with capacity 10 that doubles when outgrown.

Vector<E>

ArrayList.constructor

new Vector<E>(initialCapacity, capacityIncrement?): Vector<E>

Defined in: src/list/Vector.ts:41

Creates an empty vector with the given reported capacity.

number

initial value of capacity()

number

amount the capacity grows by when outgrown; 0 or less (the default) means it doubles

Vector<E>

IllegalArgumentException if initialCapacity is negative or not an integer

ArrayList.constructor

new Vector<E>(c): Vector<E>

Defined in: src/list/Vector.ts:46

Creates a vector holding the elements of c, in its iteration order; capacity() is their count.

Collection<E>

Vector<E>

NullPointerException if c is null or undefined

ArrayList.constructor

readonly capacityIncrement: number

Defined in: src/list/Vector.ts:31

Amount capacity() grows by when outgrown; 0 or less means it doubles. Fixed at construction.


modCount: number = 0

Defined in: src/abstract/AbstractList.ts:41

Structural modification counter. Iterators, sublists and spliterators record it and throw ConcurrentModificationException when it changes behind them. Subclasses increment it once per structural change (add, remove, clear); set leaves it alone.

ArrayList.modCount

get [RANDOM_ACCESS](): true

Defined in: src/list/ArrayList.ts:81

Marker for O(1) positional access; always true.

true

ArrayList.[RANDOM_ACCESS]

[INSPECT](): string

Defined in: src/abstract/AbstractCollection.ts:195

Node’s util.inspect hook: console.log prints the toString() form.

string

ArrayList.[INSPECT]


[iterator](): IterableIterator<E>

Defined in: src/list/ArrayList.ts:423

Returns a JS iterator over the elements in index order, for for...of and spread; fail-fast.

IterableIterator<E>

ArrayList.[iterator]


add(e): boolean

Defined in: src/list/Vector.ts:98

Appends e to the end of this vector, in amortized O(1), growing capacity() when outgrown.

E

boolean

always true

ArrayList.add

add(index, e): void

Defined in: src/list/Vector.ts:104

Inserts e at index, shifting later elements one position to the right. O(n − index); grows capacity() when outgrown.

number

E

void

ArrayIndexOutOfBoundsException if index < 0 or index > size()

ArrayList.add


addAll(c): boolean

Defined in: src/abstract/AbstractList.ts:100

Appends the elements of c in its iteration order (via addAllAt); returns true if c was not empty.

Collection<E>

boolean

NullPointerException if c is null

ArrayList.addAll

addAll(index, c): boolean

Defined in: src/abstract/AbstractList.ts:106

Inserts the elements of c at index in its iteration order (via addAllAt); returns true if c was not empty.

number

Collection<E>

boolean

IndexOutOfBoundsException if index < 0 || index > size()

NullPointerException if c is null

ArrayList.addAll


addElement(e): void

Defined in: src/list/Vector.ts:298

Appends e; same as add(e) but returns nothing.

E

void


addFirst(e): void

Defined in: src/abstract/AbstractList.ts:237

Inserts e at index 0, via addAtIndex.

E

void

UnsupportedOperationException if addAtIndex is not overridden

ArrayList.addFirst


addLast(e): void

Defined in: src/abstract/AbstractList.ts:245

Appends e at the end, via addAtIndex.

E

void

UnsupportedOperationException if addAtIndex is not overridden

ArrayList.addLast


capacity(): number

Defined in: src/list/Vector.ts:183

Returns the reported capacity: how many elements fit before it next grows. It is bookkeeping for ported code; the engine manages the real storage.

number


clear(): void

Defined in: src/list/ArrayList.ts:266

Removes all elements. Truncates the backing array, so no references to the removed elements are kept.

void

ArrayList.clear


clone(): this

Defined in: src/list/Vector.ts:144

Returns a shallow, independent copy whose capacity() equals its size; capacityIncrement is kept.

this

ArrayList.clone


contains(o): boolean

Defined in: src/list/ArrayList.ts:200

Returns true if this list contains an element equal to o (by Objects.equals). O(n) scan; null is allowed.

unknown

boolean

ArrayList.contains


containsAll(c): boolean

Defined in: src/abstract/AbstractCollection.ts:83

Returns true if this collection contains every element of c (calls contains for each).

Collection<unknown>

boolean

NullPointerException if c is null

ArrayList.containsAll


copyInto(anArray): void

Defined in: src/list/Vector.ts:233

Copies the elements, in index order, into anArray from index 0. A plain array grows if too short; a fixed-size (typed) array that is too short throws IndexOutOfBoundsException.

WritableArrayLike<E>

void

NullPointerException if anArray is null


elementAt(index): E

Defined in: src/list/Vector.ts:274

Returns the element at index; same as get. O(1).

number

E

ArrayIndexOutOfBoundsException if index < 0 or index >= size()


elements(): Enumeration<E> & Iterable<E, any, any>

Defined in: src/list/Vector.ts:241

Returns a legacy Enumeration of the elements in index order. It is index-based and not fail-fast; it is also JS-iterable and adapts to an Iterator through asIterator().

Enumeration<E> & Iterable<E, any, any>


ensureCapacity(minCapacity): void

Defined in: src/list/Vector.ts:162

Raises capacity() to at least minCapacity: it grows by capacityIncrement (or doubles when that is 0 or less), or straight to minCapacity if that is larger. Real storage is unaffected. Any positive request counts as a structural change, so open iterators fail fast afterwards.

number

void

IllegalArgumentException if minCapacity is not an integer

ArrayList.ensureCapacity


equals(o): boolean

Defined in: src/list/ArrayList.ts:428

Returns true if o is a List of any class with equal elements in the same order. O(n).

unknown

boolean

ArrayList.equals


firstElement(): E

Defined in: src/list/Vector.ts:283

Returns the first element; same as getFirst.

E

NoSuchElementException if the vector is empty


forEach(action): void

Defined in: src/list/ArrayList.ts:276

Calls action for each element, in index order.

(e) => void

void

NullPointerException if action is null

ConcurrentModificationException if action structurally modifies this list

ArrayList.forEach


get(index): E

Defined in: src/list/Vector.ts:61

Returns the element at index. O(1).

number

E

ArrayIndexOutOfBoundsException if index < 0 or index >= size()

ArrayList.get


getFirst(): E

Defined in: src/list/ArrayList.ts:386

Returns the first element. O(1).

E

NoSuchElementException if the list is empty

ArrayList.getFirst


getLast(): E

Defined in: src/list/ArrayList.ts:395

Returns the last element. O(1).

E

NoSuchElementException if the list is empty

ArrayList.getLast


hashCode(): number

Defined in: src/list/ArrayList.ts:454

Returns the list hash code, h = 31 * h + hash(e) from 1 in 32-bit arithmetic, consistent with equals. O(n).

number

ArrayList.hashCode


indexOf(o, index?): number

Defined in: src/list/Vector.ts:192

Returns the index of the first element equal to o, searching forward from index (from 0 when omitted), or -1. O(n).

unknown

number

number

IndexOutOfBoundsException if index < 0

ArrayList.indexOf


insertElementAt(e, index): void

Defined in: src/list/Vector.ts:330

Inserts e at index; same as add(index, e) with the arguments swapped. O(n − index).

E

number

void

ArrayIndexOutOfBoundsException if index < 0 or index > size()


isEmpty(): boolean

Defined in: src/list/ArrayList.ts:110

Returns true if this list has no elements. O(1).

boolean

ArrayList.isEmpty


iterator(): Iterator<E>

Defined in: src/list/ArrayList.ts:402

Returns a fail-fast iterator over the elements in index order. Its remove is O(n), like removeAt.

Iterator<E>

ArrayList.iterator


lastElement(): E

Defined in: src/list/Vector.ts:292

Returns the last element; same as getLast.

E

NoSuchElementException if the vector is empty


lastIndexOf(o, index?): number

Defined in: src/list/Vector.ts:206

Returns the index of the last element equal to o, searching backward from index (from the end when omitted), or -1. O(n).

unknown

number

number

IndexOutOfBoundsException if index >= size()

ArrayList.lastIndexOf


listIterator(index?): ListIterator<E>

Defined in: src/list/ArrayList.ts:412

Returns a fail-fast list iterator starting at index: the first next() returns the element at index. Its set is O(1); its add and remove are O(n), like the positional methods.

number = 0

start position, 0 by default

ListIterator<E>

IndexOutOfBoundsException if index < 0 or index > size()

ArrayList.listIterator


parallelStream(): Stream<E>

Defined in: src/abstract/AbstractCollection.ts:180

Returns a stream over spliterator() flagged as parallel.

Stream<E>

ArrayList.parallelStream


remove(o): boolean

Defined in: src/list/Vector.ts:307

Removes the first element equal to o (by Objects.equals), if present. O(n). Counts as a structural change even when o is not found, so open iterators fail fast afterwards.

unknown

boolean

true if an element was removed

ArrayList.remove


removeAll(c): boolean

Defined in: src/abstract/AbstractCollection.ts:108

Removes every element that c contains, through the iterator’s remove(); returns true if any was removed.

Collection<unknown>

boolean

NullPointerException if c is null

ArrayList.removeAll


removeAllElements(): void

Defined in: src/list/Vector.ts:346

Removes every element; same as clear. capacity() is unchanged.

void


removeAt(index): E

Defined in: src/list/Vector.ts:82

Removes the element at index, shifting later elements one position to the left. O(n − index). Counts as a structural change even when index is invalid.

number

E

the removed element

ArrayIndexOutOfBoundsException if index < 0 or index >= size()

ArrayList.removeAt


removeElement(o): boolean

Defined in: src/list/Vector.ts:313

Removes the first element equal to o; same as remove(o). O(n).

unknown

boolean


removeElementAt(index): void

Defined in: src/list/Vector.ts:321

Removes the element at index; same as removeAt but returns nothing. O(n − index).

number

void

ArrayIndexOutOfBoundsException if index < 0 or index >= size()


removeFirst(): E

Defined in: src/abstract/AbstractList.ts:271

Removes and returns the element at index 0, via removeAt.

E

NoSuchElementException if the list is empty

ArrayList.removeFirst


removeIf(filter): boolean

Defined in: src/list/ArrayList.ts:321

Removes every element for which filter returns true, in O(n) with one compaction pass. Every element is tested before anything is removed, so a throwing predicate, or one that modifies the list, leaves the list unchanged.

(e) => boolean

boolean

true if any element was removed

NullPointerException if filter is null

ConcurrentModificationException if filter structurally modifies this list

ArrayList.removeIf


removeLast(): E

Defined in: src/abstract/AbstractList.ts:280

Removes and returns the last element, via removeAt.

E

NoSuchElementException if the list is empty

ArrayList.removeLast


removeRange(fromIndex, toIndex): void

Defined in: src/list/ArrayList.ts:303

Removes [fromIndex, toIndex). Public so views can delegate.

number

number

void

IndexOutOfBoundsException for a bad range, before anything is removed

ArrayList.removeRange


replaceAll(operator): void

Defined in: src/list/ArrayList.ts:351

Replaces each element with the result of operator applied to it, in order. O(n). Counts as a structural change: open iterators fail fast afterwards.

(e) => E

void

NullPointerException if operator is null

ConcurrentModificationException if operator structurally modifies this list

ArrayList.replaceAll


retainAll(c): boolean

Defined in: src/abstract/AbstractCollection.ts:118

Removes every element that c does not contain, through the iterator’s remove(); returns true if any was removed.

Collection<unknown>

boolean

NullPointerException if c is null

ArrayList.retainAll


reversed(): List<E>

Defined in: src/abstract/AbstractList.ts:286

Returns a live reverse-ordered view; writes through it reach this list. reversed().reversed() is this list.

List<E>

ArrayList.reversed


set(index, e): E

Defined in: src/list/Vector.ts:71

Replaces the element at index with e. O(1); not a structural change.

number

E

E

the element previously at index

ArrayIndexOutOfBoundsException if index < 0 or index >= size()

ArrayList.set


setElementAt(e, index): void

Defined in: src/list/Vector.ts:340

Replaces the element at index; same as set(index, e) with the arguments swapped, but returns nothing. O(1), not a structural change.

E

number

void

ArrayIndexOutOfBoundsException if index < 0 or index >= size()


setSize(newSize): void

Defined in: src/list/Vector.ts:219

Sets the size: truncates the vector, or pads it with null elements. Raises capacity() if needed.

number

void

ArrayIndexOutOfBoundsException if newSize < 0 or not an integer


size(): number

Defined in: src/list/ArrayList.ts:105

Returns the number of elements. O(1).

number

ArrayList.size


sort(c?): void

Defined in: src/list/ArrayList.ts:369

Sorts this list in place. The sort is stable (equal elements keep their order) and O(n log n). Counts as a structural change: open iterators fail fast afterwards.

Comparator<E> | null = null

the comparator; null or omitted means natural ordering

void

ClassCastException if natural ordering is used and the elements have none

ConcurrentModificationException if the comparator structurally modifies this list

ArrayList.sort


spliterator(): Spliterator<E>

Defined in: src/list/ArrayList.ts:418

Returns a spliterator over the elements, used to build streams: ORDERED | SIZED | SUBSIZED, late-binding, fail-fast, splits in halves.

Spliterator<E>

ArrayList.spliterator


stream(): Stream<E>

Defined in: src/abstract/AbstractCollection.ts:175

Returns a sequential stream over spliterator().

Stream<E>

ArrayList.stream


subList(fromIndex, toIndex): List<E>

Defined in: src/abstract/AbstractList.ts:193

Returns a live view of [fromIndex, toIndex): changes through it write to this list, and a structural change made to this list directly makes the view throw ConcurrentModificationException. Carries the RandomAccess brand when this list does.

number

number

List<E>

IndexOutOfBoundsException if fromIndex < 0 or toIndex > size()

IllegalArgumentException if fromIndex > toIndex

ArrayList.subList


toArray(): E[]

Defined in: src/list/ArrayList.ts:255

Returns a new array with all elements, in index order. Changing the array does not affect this list. O(n).

E[]

ArrayList.toArray

toArray<A>(generator): A

Defined in: src/list/ArrayList.ts:260

Fills an array created by generator(size()) with the elements in index order, and returns it. O(n).

A extends WritableArrayLike<E>

(length) => A

creates the target array for a given length

A

ArrayList.toArray


toString(): string

Defined in: src/list/ArrayList.ts:465

Returns the elements in index order as [a, b, c]; an element that is this list prints as (this Collection).

string

ArrayList.toString


trimToSize(): void

Defined in: src/list/Vector.ts:174

Sets capacity() to size(). Counts as a structural change, so open iterators fail fast afterwards.

void

ArrayList.trimToSize


static of<E>(…xs): Vector<E>

Defined in: src/list/Vector.ts:136

Creates a vector holding xs in argument order. capacity() starts at 10 and grows once, as for a bulk add, if xs needs more. Called on a subclass, returns an instance of it.

E

…E[]

Vector<E>

ArrayList.of