Skip to content
Buy me a coffee

Map

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

The map interface (key to value mapping), declared under this name so Map works both as a type and as the factory object with of, ofEntries, entry, copyOf and ofLazy.

  • Map<K, V>

K

V

[iterator](): Iterator<[K, V], any, any>

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

Iterator<[K, V], any, any>

MapType.[iterator]


clear(): void

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

Removes all mappings.

void

UnsupportedOperationException if this map is unmodifiable

MapType.clear


compute(key, fn): V | null

Defined in: src/interfaces/Map.ts:163

Stores fn(key, current), where current is the mapped value or null; a null/undefined result removes the mapping (or leaves the key absent).

K

(key, value) => V | null | undefined

V | null

the new value, or null if there is now no mapping

NullPointerException if fn is null

ConcurrentModificationException if fn structurally modifies this map (hashed and tree maps detect it)

MapType.compute


computeIfAbsent(key, fn): V | null

Defined in: src/interfaces/Map.ts:148

If key is absent or mapped to null, stores fn(key) unless that is null/undefined (then nothing is stored).

K

(key) => V | null | undefined

V | null

the existing non-null value, the newly stored value, or null

NullPointerException if fn is null

ConcurrentModificationException if fn structurally modifies this map (hashed and tree maps detect it)

MapType.computeIfAbsent


computeIfPresent(key, fn): V | null

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

If key has a non-null value, replaces it with fn(key, value); a null/undefined result removes the mapping.

K

(key, value) => V | null | undefined

V | null

the new value, or null if the key was absent or has been removed

NullPointerException if fn is null

ConcurrentModificationException if fn structurally modifies this map (hashed and tree maps detect it)

MapType.computeIfPresent


containsKey(key): boolean

Defined in: src/interfaces/Map.ts:49

Returns true if this map has a mapping for key, even if it maps to null.

unknown

boolean

NullPointerException if key is null and this map rejects null keys

MapType.containsKey


containsValue(value): boolean

Defined in: src/interfaces/Map.ts:51

Returns true if one or more keys map to a value equal to value. Usually O(n).

unknown

boolean

MapType.containsValue


entrySet(): Set<MapEntry<K, V>>

Defined in: src/interfaces/Map.ts:102

Returns a live view of the mappings. Its entries are live (setValue writes through), removing from it removes the mapping, and it does not support add (UnsupportedOperationException).

Set<MapEntry<K, V>>

MapType.entrySet


equals(o): boolean

Defined in: src/interfaces/Map.ts:104

Returns true if o is a map with the same mappings, whatever its class.

unknown

boolean

MapType.equals


forEach(action): void

Defined in: src/interfaces/Map.ts:119

Calls action for each mapping, in iteration order.

(key, value) => void

void

NullPointerException if action is null

ConcurrentModificationException if action structurally modifies this map

MapType.forEach


get(key): V | null

Defined in: src/interfaces/Map.ts:56

Returns the value mapped to key, or null if there is none (or the key maps to null).

unknown

V | null

NullPointerException if key is null and this map rejects null keys

MapType.get


getOrDefault(key, defaultValue): V

Defined in: src/interfaces/Map.ts:111

Returns the value mapped to key, or defaultValue if there is no mapping. A key mapped to null returns null.

unknown

V

V

MapType.getOrDefault

getOrDefault(key, defaultValue): V | null

Defined in: src/interfaces/Map.ts:113

Returns the value mapped to key, or defaultValue (here possibly null) if there is no mapping.

unknown

V | null

V | null

MapType.getOrDefault


hashCode(): number

Defined in: src/interfaces/Map.ts:106

Returns the sum over all entries of hash(key) ^ hash(value), in 32-bit arithmetic.

number

MapType.hashCode


isEmpty(): boolean

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

Returns true if this map has no mappings.

boolean

MapType.isEmpty


keySet(): Set<K>

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

Returns a live view of the keys. Removing from it removes the mapping; it does not support add (UnsupportedOperationException).

Set<K>

MapType.keySet


merge(key, value, fn): V | null

Defined in: src/interfaces/Map.ts:171

If key is absent or mapped to null, maps it to value; otherwise stores fn(oldValue, value), and a null/undefined result removes the mapping. merge(k, 1, (a, b) => a + b) counts occurrences.

K

V

(oldValue, value) => V | null | undefined

V | null

the new value, or null if the mapping was removed

NullPointerException if value or fn is null

ConcurrentModificationException if fn structurally modifies this map (hashed and tree maps detect it)

MapType.merge


put(key, value): V | null

Defined in: src/interfaces/Map.ts:64

Maps key to value, replacing any previous value.

K

V

V | null

the previous value, or null if there was no mapping

UnsupportedOperationException if this map is unmodifiable

NullPointerException if key or value is null and this map rejects it

IllegalArgumentException if key is outside the range of a sorted map view

MapType.put


putAll(m): void

Defined in: src/interfaces/Map.ts:82

Copies every mapping of m into this map, as put would.

Map<K, V>

void

NullPointerException if m is null

UnsupportedOperationException if this map is unmodifiable

MapType.putAll


putIfAbsent(key, value): V | null

Defined in: src/interfaces/Map.ts:131

Maps key to value if it is absent or mapped to null.

K

V

V | null

the current value if it was non-null (and nothing changed), otherwise null

UnsupportedOperationException if this map is unmodifiable

MapType.putIfAbsent


remove(key): V | null

Defined in: src/interfaces/Map.ts:70

Removes the mapping for key, if present.

unknown

V | null

the removed value, or null if there was no mapping

UnsupportedOperationException if this map is unmodifiable

MapType.remove

remove(key, value): boolean

Defined in: src/interfaces/Map.ts:76

Removes the mapping for key only if it is currently mapped to a value equal to value.

unknown

unknown

boolean

true if the mapping was removed

UnsupportedOperationException if this map is unmodifiable

MapType.remove


replace(key, value): V | null

Defined in: src/interfaces/Map.ts:136

Replaces the value for key only if key currently has a mapping (even to null).

K

V

V | null

the previous value, or null if there was no mapping

MapType.replace

replace(key, oldValue, newValue): boolean

Defined in: src/interfaces/Map.ts:141

Replaces the value for key with newValue only if it is currently mapped to a value equal to oldValue.

K

V

V

boolean

true if the value was replaced

MapType.replace


replaceAll(fn): void

Defined in: src/interfaces/Map.ts:125

Replaces each value with fn(key, value), in iteration order.

(key, value) => V

void

NullPointerException if fn is null, or it returns null and this map rejects null values

UnsupportedOperationException if this map is unmodifiable

MapType.replaceAll


size(): number

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

Returns the number of mappings.

number

MapType.size


toString(): string

Defined in: src/interfaces/Map.ts:108

Returns the mappings in iteration order as {k1=v1, k2=v2}; a key or value that is this map prints as (this Map).

string

MapType.toString


values(): Collection<V>

Defined in: src/interfaces/Map.ts:97

Returns a live view of the values. Removing from it removes the mapping; it does not support add (UnsupportedOperationException).

Collection<V>

MapType.values