ReadonlyrevisionA number that changes on every change to the contents — adding, removing or replacing an element — and never on a read. Watch it to detect changes; its exact values are unspecified. Time: O(1).
ReadonlysizeThe number of elements. Time: O(1).
The value-equality protocol; delegates to equals. Time: as equals.
The value-equality protocol: a hash consistent with equals, computed with hash.
Time: as the implementation documents.
Returns an iterator over the elements in iteration order.
Time: O(1) to create; each step amortised O(1) unless the implementation documents otherwise.
A new iterator.
Adds element and returns the collection, so calls chain. A collection that refuses
duplicates is left unchanged. Time: as the implementation documents.
The element to add.
The collection.
Adds every element of elements, in order, after reading them all. If an error is thrown
part-way, the elements added before it stay.
Time: O(m) plus m additions.
The elements to add.
true when any element was added.
Adds element at the front and returns the collection.
Time: as the implementation documents.
The element to add.
The collection.
Adds element at the end and returns the collection.
Time: as the implementation documents.
The element to add.
The collection.
Removes every element. Time: as the implementation documents.
Removes one element equal to element (the first, where order is defined). Time: as the implementation documents.
The value to remove.
true when an element was removed.
Returns whether other is equal to this collection, as the collection's family defines;
otherwise only the collection itself. Time: as the implementation documents.
Any value.
true when equal.
Calls action(element, index, list) for each element in index order, with this set to
thisArg, as Array.prototype.forEach does.
Time: O(n) plus the calls.
Returns the element at index.
Time: as the implementation documents.
An integer with 0 <= index < size.
The element.
Returns whether some element is equal to element under the collection's equality
(SameValueZero unless the collection says otherwise). Time: as the implementation documents.
The value to look for.
true when an equal element is present.
Returns the lowest index whose element is equal to element under SameValueZero (so NaN
is found), or -1.
Time: O(n).
The value to look for.
The index, or -1.
Inserts element at index, shifting later elements up by one, and returns the list.
Time: as the implementation documents.
An integer with 0 <= index <= size.
The element to insert.
The list.
Inserts every element of elements at index, in order, after reading them all.
Time: as the implementation documents.
An integer with 0 <= index <= size.
The elements to insert.
true when any element was inserted.
Returns whether the collection has no elements.
Time: O(1).
size === 0.
Returns the highest index whose element is equal to element under SameValueZero, or -1.
Time: O(n).
The value to look for.
The index, or -1.
Returns a cursor positioned before index (0 when omitted).
Time: O(1).
Optionalindex: number
An integer with 0 <= index <= size.
A new cursor.
Removes every element equal to one in elements. Decides first, so an error while deciding
removes nothing. Time: as the implementation documents.
The elements to remove.
true when any element was removed.
Removes and returns the element at index, shifting later elements down by one.
Time: as the implementation documents.
An integer with 0 <= index < size.
The removed element.
Removes and returns the first element.
Time: as the implementation documents.
The removed element.
Calls predicate(element, index, list) on every element (indexes before any removal), then
removes those for which it returned a truthy value; an error from predicate removes nothing.
Time: O(n) plus the calls.
true when any element was removed.
Removes and returns the last element.
Time: as the implementation documents.
The removed element.
Replaces each element with op(element, index, list), in index order. If op throws, the
elements before it are already replaced and the rest are unchanged. Open iterators stay valid.
Time: O(n) plus the calls.
Removes every element not equal to one in elements. Decides first, so an error while
deciding removes nothing. Time: as the implementation documents.
The elements to keep.
true when any element was removed.
Sorts the list in place, keeping equal elements in their order (stable), and returns it.
Without a comparator, natural order is used. null and undefined reach the comparator like
any other element. If the comparator throws or returns something other than a number, the
list is left as it was.
Time: O(n log n); at most n·⌈log₂ n⌉ comparator calls.
Optionalcomparator: Comparator<E>
The order; natural order when omitted.
The list.
Returns a live view of the elements from from (inclusive) to to (exclusive); changes
through the view reach this list. Once this list's structure changes other than through the
view, the view throws ConcurrentModificationError.
Time: O(1).
Start of the range, inclusive.
End of the range, exclusive.
The view.
Returns a new array of the elements in iteration order; changing it does not change the collection.
Time: O(n).
A new array.
Returns a new array of the elements, so JSON.stringify writes the collection as an array.
Time: O(n).
A new array.
Returns the class name, size and elements, e.g. ArrayList(3) [1, 2, 'a'].
Time: O(length of the output) for flat contents; each level of nested arrays or collections copies its text once more.
The text.
A list that can be changed: ordered, indexed from 0, duplicates allowed.
addappends;insertputs an element at a position.delete(element)removes by value;removeAt(index)by position.Example