Skip to content
Buy me a coffee

Collection

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

The root interface of the collection hierarchy: a group of elements.

Membership tests (contains, remove, containsAll, …) use Objects.equals: the element’s own equals() when it has one, Dates by time, otherwise SameValueZero; never plain ===. Mutating methods are optional operations: an unmodifiable or immutable collection throws UnsupportedOperationException from them. Implementations that reject null throw NullPointerException when given one. Iteration is fail-fast: a structural change made other than through the iterator makes the next step throw ConcurrentModificationException. Collections are also iterable with for..of and spread.

  • Iterable<E>

E

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

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

Iterator<E, any, any>

Iterable.[iterator]


add(e): boolean

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

Ensures this collection contains e.

E

boolean

true if the collection changed (a set returns false for a duplicate)

UnsupportedOperationException if this collection is unmodifiable

NullPointerException if e is null and this collection rejects null

IllegalArgumentException if some property of e prevents adding it (for example a key outside a sorted view’s range)

IllegalStateException if a capacity-bounded queue is full


addAll(c): boolean

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

Adds every element of c, in c’s iteration order. c is copied first, so addAll(this) terminates.

Collection<E>

boolean

true if this collection changed

NullPointerException if c is null, or contains null and this collection rejects null

UnsupportedOperationException if this collection is unmodifiable


clear(): void

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

Removes all elements.

void

UnsupportedOperationException if this collection is unmodifiable


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)


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


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


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


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


isEmpty(): boolean

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

Returns true if this collection has no elements.

boolean


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>


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>


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


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


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


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


size(): number

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

Returns the number of elements.

number


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>


stream(): Stream<E>

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

Returns a sequential stream over this collection.

Stream<E>


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[]

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


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