Skip to content
Kotlin

kotlin.collections.Map API Reference

Kotlin's Map<K, V> — an immutable key-value collection; MutableMap<K, V> adds mutation.

By EZ4Code Team

Map<K, V>

A collection that holds pairs of keys and values. Map is read-only; MutableMap supports modification.

Map.size: Int

Returns the number of key-value pairs in this map.

Returns: Int

Map.containsKey(key: K): Boolean

Returns true if the map contains the specified key.

Returns: Boolean

Map.containsValue(value: V): Boolean

Returns true if the map maps one or more keys to the specified value.

Returns: Boolean

Map.get(key: K): V?

Returns the value corresponding to the given key, or null if not present.

Returns: V?

MutableMap.put(key: K, value: V): V?

Associates the specified value with the specified key. Returns the previous value (or null).

Returns: V?

MutableMap.remove(key: K): V?

Removes the specified key and its corresponding value. Returns the removed value (or null).

Returns: V?

Map.forEach { (key, value) -> Unit }

Performs the given action on each entry in the map.

Returns: Unit

Map.keys: Set<K>

Returns a read-only Set of all keys in this map.

Returns: Set<K>

More Kotlin API References