Skip to content
Buy me a coffee

List

Defined in: src/immutable/ImmutableCollections.ts:776

The list interface (ordered, index-based collection), declared under this name so List works both as a type and as the factory object with of, copyOf and ofLazy.

  • List<E>

E

[iterator](): Iterator<E, any, any>

Defined in: site/node_modules/typescript/lib/lib.es2015.iterable.d.ts:47

Iterator<E, any, any>

ListType.[iterator]


add(e): boolean

Defined in: src/interfaces/List.ts:21

Appends e to the end of this list.

E

boolean

always true

UnsupportedOperationException if this list is unmodifiable

NullPointerException if e is null and this list rejects null

ListType.add

add(index, e): void

Defined in: src/interfaces/List.ts:27

Inserts e at index, shifting the element there and all later ones one position to the right.

number

E

void

IndexOutOfBoundsException if index < 0 or index > size()

UnsupportedOperationException if this list is unmodifiable

ListType.add


addAll(c): boolean

Defined in: src/interfaces/List.ts:34

Appends every element of c, in c’s iteration order.

Collection<E>

boolean

true if this list changed (c was not empty)

NullPointerException if c is null

UnsupportedOperationException if this list is unmodifiable

ListType.addAll

addAll(index, c): boolean

Defined in: src/interfaces/List.ts:42

Inserts every element of c at index, in c’s iteration order, shifting later elements right.

number

Collection<E>

boolean

true if this list changed (c was not empty)

IndexOutOfBoundsException if index < 0 or index > size()

NullPointerException if c is null

UnsupportedOperationException if this list is unmodifiable

ListType.addAll


addFirst(e): void

Defined in: src/interfaces/Collection.ts:133

Adds e as the first element (for a set that already holds it, moves it to the front).

E

void

UnsupportedOperationException if this collection is unmodifiable or sorted

NullPointerException if e is null and this collection rejects null

ListType.addFirst


addLast(e): void

Defined in: src/interfaces/Collection.ts:139

Adds e as the last element (for a set that already holds it, moves it to the end).

E

void

UnsupportedOperationException if this collection is unmodifiable or sorted

NullPointerException if e is null and this collection rejects null

ListType.addLast


clear(): void

Defined in: src/interfaces/Collection.ts:99

Removes all elements.

void

UnsupportedOperationException if this collection is unmodifiable

ListType.clear


contains(o): boolean

Defined in: src/interfaces/Collection.ts:37

Returns true if this collection contains an element equal to o (by Objects.equals).

unknown

boolean

NullPointerException if o is null and this collection rejects null (for example the immutable collections and sorted collections with natural ordering)

ListType.contains


containsAll(c): boolean

Defined in: src/interfaces/Collection.ts:66

Returns true if this collection contains every element of c.

Collection<unknown>

boolean

NullPointerException if c is null

ListType.containsAll


equals(o): boolean

Defined in: src/interfaces/Collection.ts:105

Compares this collection with o for equality. A List equals any other List with the same elements in the same order; a Set equals any other Set with the same elements; other collections (queues, deques, values() views) use identity.

unknown

boolean

ListType.equals


forEach(action): void

Defined in: src/interfaces/Collection.ts:27

Calls action for each element, in iteration order.

(e) => void

void

NullPointerException if action is null

ConcurrentModificationException if action structurally modifies this collection

ListType.forEach


get(index): E

Defined in: src/interfaces/List.ts:47

Returns the element at index.

number

E

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

ListType.get


getFirst(): E

Defined in: src/interfaces/Collection.ts:144

Returns the first element.

E

NoSuchElementException if this collection is empty

ListType.getFirst


getLast(): E

Defined in: src/interfaces/Collection.ts:149

Returns the last element.

E

NoSuchElementException if this collection is empty

ListType.getLast


hashCode(): number

Defined in: src/interfaces/Collection.ts:110

Returns a hash code consistent with equals. A list hashes as h = 31 * h + hash(e) starting from 1, a set as the sum of its element hashes (both in 32-bit arithmetic); other collections use an identity hash.

number

ListType.hashCode


indexOf(o): number

Defined in: src/interfaces/List.ts:63

Returns the index of the first element equal to o (by Objects.equals), or -1 if there is none.

unknown

number

ListType.indexOf


isEmpty(): boolean

Defined in: src/interfaces/Collection.ts:31

Returns true if this collection has no elements.

boolean

ListType.isEmpty


iterator(): Iterator<E>

Defined in: src/interfaces/Collection.ts:21

Returns a fail-fast iterator over the elements, in this collection’s encounter order (if it has one). Its remove() throws UnsupportedOperationException on an unmodifiable collection.

Iterator<E>

ListType.iterator


lastIndexOf(o): number

Defined in: src/interfaces/List.ts:65

Returns the index of the last element equal to o (by Objects.equals), or -1 if there is none.

unknown

number

ListType.lastIndexOf


listIterator(index?): ListIterator<E>

Defined in: src/interfaces/List.ts:71

Returns a fail-fast list iterator starting at index: the first next() returns the element at index.

number

start position, 0 by default

ListIterator<E>

IndexOutOfBoundsException if index < 0 or index > size()

ListType.listIterator


parallelStream(): Stream<E>

Defined in: src/interfaces/Collection.ts:118

Returns a stream flagged as parallel; it is evaluated sequentially (JS is single-threaded).

Stream<E>

ListType.parallelStream


remove(o): boolean

Defined in: src/interfaces/Collection.ts:61

Removes one element equal to o, if present.

unknown

boolean

true if an element was removed

UnsupportedOperationException if this collection is unmodifiable

NullPointerException if o is null and this collection rejects null

ListType.remove


removeAll(c): boolean

Defined in: src/interfaces/Collection.ts:80

Removes every element that is also contained in c.

Collection<unknown>

boolean

true if this collection changed

NullPointerException if c is null

UnsupportedOperationException if this collection is unmodifiable

ListType.removeAll


removeAt(index): E

Defined in: src/interfaces/List.ts:61

Removes the element at index, shifting later elements one position to the left.

number

E

the removed element

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

UnsupportedOperationException if this list is unmodifiable

ListType.removeAt


removeFirst(): E

Defined in: src/interfaces/Collection.ts:155

Removes and returns the first element.

E

NoSuchElementException if this collection is empty

UnsupportedOperationException if this collection is unmodifiable

ListType.removeFirst


removeIf(filter): boolean

Defined in: src/interfaces/Collection.ts:87

Removes every element for which filter returns true.

(e) => boolean

boolean

true if any element was removed

NullPointerException if filter is null

UnsupportedOperationException if this collection is unmodifiable and an element matches

ListType.removeIf


removeLast(): E

Defined in: src/interfaces/Collection.ts:161

Removes and returns the last element.

E

NoSuchElementException if this collection is empty

UnsupportedOperationException if this collection is unmodifiable

ListType.removeLast


replaceAll(operator): void

Defined in: src/interfaces/List.ts:85

Replaces each element with the result of operator applied to it, in order.

(e) => E

void

NullPointerException if operator is null

UnsupportedOperationException if this list does not support set

ListType.replaceAll


retainAll(c): boolean

Defined in: src/interfaces/Collection.ts:94

Keeps only the elements that are also contained in c, removing all others.

Collection<unknown>

boolean

true if this collection changed

NullPointerException if c is null

UnsupportedOperationException if this collection is unmodifiable

ListType.retainAll


reversed(): List<E>

Defined in: src/interfaces/List.ts:94

Returns a live reverse-ordered view: changes through either side are visible in the other. Random-access when this list is.

List<E>

ListType.reversed


set(index, e): E

Defined in: src/interfaces/List.ts:54

Replaces the element at index with e. Not a structural change, so open iterators stay valid.

number

E

E

the element previously at index

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

UnsupportedOperationException if this list does not support set

ListType.set


size(): number

Defined in: src/interfaces/Collection.ts:29

Returns the number of elements.

number

ListType.size


sort(c?): void

Defined in: src/interfaces/List.ts:92

Sorts this list in place. The sort is stable: equal elements keep their relative order.

Comparator<E> | null

the comparator; null or omitted means natural ordering

void

ClassCastException if natural ordering is used and the elements have none

UnsupportedOperationException if this list does not support set

ListType.sort


spliterator(): Spliterator<E>

Defined in: src/interfaces/Collection.ts:114

Returns a spliterator over the elements, used to build streams. Fail-fast like the iterator.

Spliterator<E>

ListType.spliterator


stream(): Stream<E>

Defined in: src/interfaces/Collection.ts:116

Returns a sequential stream over this collection.

Stream<E>

ListType.stream


subList(fromIndex, toIndex): List<E>

Defined in: src/interfaces/List.ts:79

Returns a live view of the range [fromIndex, toIndex): changes through either side are visible in the other. A structural change made to this list other than through the view makes the view fail fast (ConcurrentModificationException). The view is random-access when this list is.

number

number

List<E>

IndexOutOfBoundsException if fromIndex < 0 or toIndex > size()

IllegalArgumentException if fromIndex > toIndex

ListType.subList


toArray(): E[]

Defined in: src/interfaces/Collection.ts:39

Returns a new array with all elements, in iteration order. Changing the array does not affect this collection.

E[]

ListType.toArray

toArray<A>(generator): A

Defined in: src/interfaces/Collection.ts:44

Fills an array created by generator(size()), in iteration order, and returns it; e.g. n => new Float64Array(n).

A extends WritableArrayLike<E>

(length) => A

creates the target array for a given length

A

ListType.toArray


toString(): string

Defined in: src/interfaces/Collection.ts:112

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

string

ListType.toString