ArrayList
Defined in: src/list/ArrayList.ts:35
Resizable list backed by a dense native array; the default List implementation.
get and set are O(1), appending is amortized O(1), and inserting or removing at index i
is O(n − i) because the tail shifts (so addFirst/removeFirst are O(n)). contains, indexOf
and remove(o) are O(n) scans; sort is a stable O(n log n). Permits null and undefined
elements. Iterates in index order; iterators, forEach and views are fail-fast, and sort
and replaceAll count as structural changes (set does not).
The backing array never contains holes: every index in [0, size) holds a value, so the engine keeps it in a packed elements kind.
Extends
Section titled “Extends”AbstractList<E>
Extended by
Section titled “Extended by”Type Parameters
Section titled “Type Parameters”E
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ArrayList<
E>():ArrayList<E>
Defined in: src/list/ArrayList.ts:40
Creates an empty list.
Returns
Section titled “Returns”ArrayList<E>
Overrides
Section titled “Overrides”Constructor
Section titled “Constructor”new ArrayList<
E>(initialCapacity):ArrayList<E>
Defined in: src/list/ArrayList.ts:47
Creates an empty list. initialCapacity is validated but only a hint: nothing is
preallocated, since preallocating would create holes in the backing array.
Parameters
Section titled “Parameters”initialCapacity
Section titled “initialCapacity”number
expected number of elements
Returns
Section titled “Returns”ArrayList<E>
Throws
Section titled “Throws”IllegalArgumentException if initialCapacity is negative or not an integer
Overrides
Section titled “Overrides”AbstractList<E>.constructor
Constructor
Section titled “Constructor”new ArrayList<
E>(c):ArrayList<E>
Defined in: src/list/ArrayList.ts:52
Creates a list holding the elements of c, in its iteration order. O(n).
Parameters
Section titled “Parameters”Collection<E>
Returns
Section titled “Returns”ArrayList<E>
Throws
Section titled “Throws”NullPointerException if c is null or undefined
Overrides
Section titled “Overrides”AbstractList<E>.constructor
Properties
Section titled “Properties”modCount
Section titled “modCount”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.
Inherited from
Section titled “Inherited from”Accessors
Section titled “Accessors”[RANDOM_ACCESS]
Section titled “[RANDOM_ACCESS]”Get Signature
Section titled “Get Signature”get [RANDOM_ACCESS]():
true
Defined in: src/list/ArrayList.ts:81
Marker for O(1) positional access; always true.
Returns
Section titled “Returns”true
Methods
Section titled “Methods”[INSPECT]()
Section titled “[INSPECT]()”[INSPECT]():
string
Defined in: src/abstract/AbstractCollection.ts:195
Node’s util.inspect hook: console.log prints the toString() form.
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”[iterator]()
Section titled “[iterator]()”[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.
Returns
Section titled “Returns”IterableIterator<E>
Overrides
Section titled “Overrides”Call Signature
Section titled “Call Signature”add(
e):boolean
Defined in: src/list/ArrayList.ts:143
Appends e to the end of this list, in amortized O(1). null and undefined are allowed.
Parameters
Section titled “Parameters”E
Returns
Section titled “Returns”boolean
always true
Overrides
Section titled “Overrides”Call Signature
Section titled “Call Signature”add(
index,e):void
Defined in: src/list/ArrayList.ts:149
Inserts e at index, shifting the element there and all later ones one position to the right.
O(n − index).
Parameters
Section titled “Parameters”number
E
Returns
Section titled “Returns”void
Throws
Section titled “Throws”IndexOutOfBoundsException if index < 0 or index > size()
Overrides
Section titled “Overrides”addAll()
Section titled “addAll()”Call Signature
Section titled “Call Signature”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.
Parameters
Section titled “Parameters”Collection<E>
Returns
Section titled “Returns”boolean
Throws
Section titled “Throws”NullPointerException if c is null
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”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.
Parameters
Section titled “Parameters”number
Collection<E>
Returns
Section titled “Returns”boolean
Throws
Section titled “Throws”IndexOutOfBoundsException if index < 0 || index > size()
Throws
Section titled “Throws”NullPointerException if c is null
Inherited from
Section titled “Inherited from”addFirst()
Section titled “addFirst()”addFirst(
e):void
Defined in: src/abstract/AbstractList.ts:237
Inserts e at index 0, via addAtIndex.
Parameters
Section titled “Parameters”E
Returns
Section titled “Returns”void
Throws
Section titled “Throws”UnsupportedOperationException if addAtIndex is not overridden
Inherited from
Section titled “Inherited from”addLast()
Section titled “addLast()”addLast(
e):void
Defined in: src/abstract/AbstractList.ts:245
Appends e at the end, via addAtIndex.
Parameters
Section titled “Parameters”E
Returns
Section titled “Returns”void
Throws
Section titled “Throws”UnsupportedOperationException if addAtIndex is not overridden
Inherited from
Section titled “Inherited from”clear()
Section titled “clear()”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.
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”clone()
Section titled “clone()”clone():
this
Defined in: src/list/ArrayList.ts:100
Returns a shallow, independent copy of the same runtime class, in O(n).
Returns
Section titled “Returns”this
contains()
Section titled “contains()”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.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”boolean
Overrides
Section titled “Overrides”containsAll()
Section titled “containsAll()”containsAll(
c):boolean
Defined in: src/abstract/AbstractCollection.ts:83
Returns true if this collection contains every element of c (calls contains for each).
Parameters
Section titled “Parameters”Collection<unknown>
Returns
Section titled “Returns”boolean
Throws
Section titled “Throws”NullPointerException if c is null
Inherited from
Section titled “Inherited from”ensureCapacity()
Section titled “ensureCapacity()”ensureCapacity(
_minCapacity):void
Defined in: src/list/ArrayList.ts:89
Does nothing: capacity is only a hint, and the native array manages its own storage. Kept for API compatibility; the argument is not validated.
Parameters
Section titled “Parameters”_minCapacity
Section titled “_minCapacity”number
Returns
Section titled “Returns”void
equals()
Section titled “equals()”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).
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”boolean
Overrides
Section titled “Overrides”forEach()
Section titled “forEach()”forEach(
action):void
Defined in: src/list/ArrayList.ts:276
Calls action for each element, in index order.
Parameters
Section titled “Parameters”action
Section titled “action”(e) => void
Returns
Section titled “Returns”void
Throws
Section titled “Throws”NullPointerException if action is null
Throws
Section titled “Throws”ConcurrentModificationException if action structurally modifies this list
Overrides
Section titled “Overrides”get(
index):E
Defined in: src/list/ArrayList.ts:118
Returns the element at index. O(1).
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”E
Throws
Section titled “Throws”IndexOutOfBoundsException if index < 0 or index >= size()
Overrides
Section titled “Overrides”getFirst()
Section titled “getFirst()”getFirst():
E
Defined in: src/list/ArrayList.ts:386
Returns the first element. O(1).
Returns
Section titled “Returns”E
Throws
Section titled “Throws”NoSuchElementException if the list is empty
Overrides
Section titled “Overrides”getLast()
Section titled “getLast()”getLast():
E
Defined in: src/list/ArrayList.ts:395
Returns the last element. O(1).
Returns
Section titled “Returns”E
Throws
Section titled “Throws”NoSuchElementException if the list is empty
Overrides
Section titled “Overrides”hashCode()
Section titled “hashCode()”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).
Returns
Section titled “Returns”number
Overrides
Section titled “Overrides”indexOf()
Section titled “indexOf()”indexOf(
o):number
Defined in: src/list/ArrayList.ts:208
Returns the index of the first element equal to o (by Objects.equals), or -1 if there is none.
O(n) scan from the front; NaN matches NaN.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”number
Overrides
Section titled “Overrides”isEmpty()
Section titled “isEmpty()”isEmpty():
boolean
Defined in: src/list/ArrayList.ts:110
Returns true if this list has no elements. O(1).
Returns
Section titled “Returns”boolean
Overrides
Section titled “Overrides”iterator()
Section titled “iterator()”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.
Returns
Section titled “Returns”Iterator<E>
Overrides
Section titled “Overrides”lastIndexOf()
Section titled “lastIndexOf()”lastIndexOf(
o):number
Defined in: src/list/ArrayList.ts:234
Returns the index of the last element equal to o (by Objects.equals), or -1 if there is none.
O(n) scan from the back; NaN matches NaN.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”number
Overrides
Section titled “Overrides”listIterator()
Section titled “listIterator()”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.
Parameters
Section titled “Parameters”index?
Section titled “index?”number = 0
start position, 0 by default
Returns
Section titled “Returns”ListIterator<E>
Throws
Section titled “Throws”IndexOutOfBoundsException if index < 0 or index > size()
Overrides
Section titled “Overrides”parallelStream()
Section titled “parallelStream()”parallelStream():
Stream<E>
Defined in: src/abstract/AbstractCollection.ts:180
Returns a stream over spliterator() flagged as parallel.
Returns
Section titled “Returns”Stream<E>
Inherited from
Section titled “Inherited from”remove()
Section titled “remove()”remove(
o):boolean
Defined in: src/list/ArrayList.ts:192
Removes the first element equal to o (by Objects.equals), if present. O(n): a linear scan,
then a shift of the tail.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”boolean
true if an element was removed
Overrides
Section titled “Overrides”removeAll()
Section titled “removeAll()”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.
Parameters
Section titled “Parameters”Collection<unknown>
Returns
Section titled “Returns”boolean
Throws
Section titled “Throws”NullPointerException if c is null
Inherited from
Section titled “Inherited from”removeAt()
Section titled “removeAt()”removeAt(
index):E
Defined in: src/list/ArrayList.ts:175
Removes the element at index, shifting later elements one position to the left.
O(n − index); O(1) for the last element.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”E
the removed element
Throws
Section titled “Throws”IndexOutOfBoundsException if index < 0 or index >= size()
Overrides
Section titled “Overrides”removeFirst()
Section titled “removeFirst()”removeFirst():
E
Defined in: src/abstract/AbstractList.ts:271
Removes and returns the element at index 0, via removeAt.
Returns
Section titled “Returns”E
Throws
Section titled “Throws”NoSuchElementException if the list is empty
Inherited from
Section titled “Inherited from”removeIf()
Section titled “removeIf()”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.
Parameters
Section titled “Parameters”filter
Section titled “filter”(e) => boolean
Returns
Section titled “Returns”boolean
true if any element was removed
Throws
Section titled “Throws”NullPointerException if filter is null
Throws
Section titled “Throws”ConcurrentModificationException if filter structurally modifies this list
Overrides
Section titled “Overrides”removeLast()
Section titled “removeLast()”removeLast():
E
Defined in: src/abstract/AbstractList.ts:280
Removes and returns the last element, via removeAt.
Returns
Section titled “Returns”E
Throws
Section titled “Throws”NoSuchElementException if the list is empty
Inherited from
Section titled “Inherited from”removeRange()
Section titled “removeRange()”removeRange(
fromIndex,toIndex):void
Defined in: src/list/ArrayList.ts:303
Removes [fromIndex, toIndex). Public so views can delegate.
Parameters
Section titled “Parameters”fromIndex
Section titled “fromIndex”number
toIndex
Section titled “toIndex”number
Returns
Section titled “Returns”void
Throws
Section titled “Throws”IndexOutOfBoundsException for a bad range, before anything is removed
Overrides
Section titled “Overrides”replaceAll()
Section titled “replaceAll()”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.
Parameters
Section titled “Parameters”operator
Section titled “operator”(e) => E
Returns
Section titled “Returns”void
Throws
Section titled “Throws”NullPointerException if operator is null
Throws
Section titled “Throws”ConcurrentModificationException if operator structurally modifies this list
Overrides
Section titled “Overrides”retainAll()
Section titled “retainAll()”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.
Parameters
Section titled “Parameters”Collection<unknown>
Returns
Section titled “Returns”boolean
Throws
Section titled “Throws”NullPointerException if c is null
Inherited from
Section titled “Inherited from”reversed()
Section titled “reversed()”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.
Returns
Section titled “Returns”List<E>
Inherited from
Section titled “Inherited from”set(
index,e):E
Defined in: src/list/ArrayList.ts:130
Replaces the element at index with e. O(1); not a structural change, so open iterators stay valid.
Parameters
Section titled “Parameters”number
E
Returns
Section titled “Returns”E
the element previously at index
Throws
Section titled “Throws”IndexOutOfBoundsException if index < 0 or index >= size()
Overrides
Section titled “Overrides”size()
Section titled “size()”size():
number
Defined in: src/list/ArrayList.ts:105
Returns the number of elements. O(1).
Returns
Section titled “Returns”number
Overrides
Section titled “Overrides”sort()
Section titled “sort()”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.
Parameters
Section titled “Parameters”Comparator<E> | null = null
the comparator; null or omitted means natural ordering
Returns
Section titled “Returns”void
Throws
Section titled “Throws”ClassCastException if natural ordering is used and the elements have none
Throws
Section titled “Throws”ConcurrentModificationException if the comparator structurally modifies this list
Overrides
Section titled “Overrides”spliterator()
Section titled “spliterator()”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.
Returns
Section titled “Returns”Spliterator<E>
Overrides
Section titled “Overrides”stream()
Section titled “stream()”stream():
Stream<E>
Defined in: src/abstract/AbstractCollection.ts:175
Returns a sequential stream over spliterator().
Returns
Section titled “Returns”Stream<E>
Inherited from
Section titled “Inherited from”subList()
Section titled “subList()”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.
Parameters
Section titled “Parameters”fromIndex
Section titled “fromIndex”number
toIndex
Section titled “toIndex”number
Returns
Section titled “Returns”List<E>
Throws
Section titled “Throws”IndexOutOfBoundsException if fromIndex < 0 or toIndex > size()
Throws
Section titled “Throws”IllegalArgumentException if fromIndex > toIndex
Inherited from
Section titled “Inherited from”toArray()
Section titled “toArray()”Call Signature
Section titled “Call Signature”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).
Returns
Section titled “Returns”E[]
Overrides
Section titled “Overrides”Call Signature
Section titled “Call Signature”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).
Type Parameters
Section titled “Type Parameters”A extends WritableArrayLike<E>
Parameters
Section titled “Parameters”generator
Section titled “generator”(length) => A
creates the target array for a given length
Returns
Section titled “Returns”A
Overrides
Section titled “Overrides”toString()
Section titled “toString()”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).
Returns
Section titled “Returns”string
Overrides
Section titled “Overrides”trimToSize()
Section titled “trimToSize()”trimToSize():
void
Defined in: src/list/ArrayList.ts:95
Does not change storage (the native array manages it), but counts as a structural change, so open iterators fail fast afterwards.
Returns
Section titled “Returns”void
staticof<E>(…xs):ArrayList<E>
Defined in: src/list/ArrayList.ts:68
Creates a mutable list holding xs in argument order. Unlike List.of, the result is
modifiable and may hold null and undefined. Called on a subclass, returns an instance of it.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”…E[]
Returns
Section titled “Returns”ArrayList<E>