MutableMap

interface MutableMap<K, V> : Map<K, V> (source)

A modifiable collection that holds pairs of objects (keys and values) and supports efficiently retrieving the value corresponding to each key. Map keys are unique; the map holds only one value for each key.

Since Kotlin

1.0
interface MutableMap<K, V> : Map<K, V> (source)

A modifiable collection that holds pairs of objects (keys and values) and supports efficiently retrieving the value corresponding to each key. Map keys are unique; the map holds only one value for each key.

Since Kotlin

1.1

Parameters

K

the type of map keys. The map is invariant in its key type.

V

the type of map values. The mutable map is invariant in its value type.

K

the type of map keys. The map is invariant in its key type.

V

the type of map values. The mutable map is invariant in its value type.

Types

Link copied to clipboard
interface MutableEntry<K, V> : Map.Entry<K, V>

Represents a key/value pair held by a MutableMap.

Since Kotlin 1.0
interface MutableEntry<K, V> : Map.Entry<K, V>

Represents a key/value pair held by a MutableMap.

Since Kotlin 1.1

Functions

Link copied to clipboard
abstract fun clear()

Removes all elements from this map.

Since Kotlin 1.0
abstract fun clear()

Removes all elements from this map.

Since Kotlin 1.1
Link copied to clipboard
abstract fun containsKey(key: K): Boolean

Returns true if the map contains the specified key.

Since Kotlin 1.0
abstract fun containsKey(key: K): Boolean

Returns true if the map contains the specified key.

Since Kotlin 1.1
Link copied to clipboard
abstract fun containsValue(value: V): Boolean

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

Since Kotlin 1.0
abstract fun containsValue(value: V): Boolean

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

Since Kotlin 1.1
Link copied to clipboard
abstract operator fun get(key: K): V?

Returns the value corresponding to the given key, or null if such a key is not present in the map.

Since Kotlin 1.0
abstract operator fun get(key: K): V?

Returns the value corresponding to the given key, or null if such a key is not present in the map.

Since Kotlin 1.1
Link copied to clipboard
open fun getOrDefault(key: K, defaultValue: V): V

Returns the value corresponding to the given key, or defaultValue if such a key is not present in the map.

Since Kotlin 1.1
open fun getOrDefault(key: K, defaultValue: V): V

Returns the value corresponding to the given key, or defaultValue if such a key is not present in the map.

Since Kotlin 1.1
Link copied to clipboard
abstract fun isEmpty(): Boolean

Returns true if the map is empty (contains no elements), false otherwise.

Since Kotlin 1.0
abstract fun isEmpty(): Boolean

Returns true if the map is empty (contains no elements), false otherwise.

Since Kotlin 1.1
Link copied to clipboard
abstract fun put(key: K, value: V): V?

Associates the specified value with the specified key in the map.

Since Kotlin 1.0
abstract fun put(key: K, value: V): V?

Associates the specified value with the specified key in the map.

Since Kotlin 1.1
Link copied to clipboard
abstract fun putAll(from: Map<out K, V>)

Updates this map with key/value pairs from the specified map from.

Since Kotlin 1.0
abstract fun putAll(from: Map<out K, V>)

Updates this map with key/value pairs from the specified map from.

Since Kotlin 1.1
Link copied to clipboard
abstract fun remove(key: K): V?

Removes the specified key and its corresponding value from this map.

Since Kotlin 1.0
open fun remove(key: K, value: V): Boolean

Removes the entry for the specified key only if it is mapped to the specified value.

Since Kotlin 1.1
abstract fun remove(key: K): V?

Removes the specified key and its corresponding value from this map.

Since Kotlin 1.1
open fun remove(key: K, value: V): Boolean

Removes the entry for the specified key only if it is mapped to the specified value.

Since Kotlin 1.1

Properties

Link copied to clipboard
abstract override val entries: MutableSet<MutableMap.MutableEntry<K, V>>

Returns a MutableSet of all key/value pairs in this map.

Since Kotlin 1.0
abstract override val entries: MutableSet<MutableMap.MutableEntry<K, V>>

Returns a MutableSet of all key/value pairs in this map.

Since Kotlin 1.1
Link copied to clipboard
abstract override val keys: MutableSet<K>

Returns a MutableSet of all keys in this map.

Since Kotlin 1.0
abstract override val keys: MutableSet<K>

Returns a MutableSet of all keys in this map.

Since Kotlin 1.1
Link copied to clipboard
abstract val size: Int

Returns the number of key/value pairs in the map.

Since Kotlin 1.0
abstract val size: Int

Returns the number of key/value pairs in the map.

Since Kotlin 1.1
Link copied to clipboard
abstract override val values: MutableCollection<V>

Returns a MutableCollection of all values in this map. Note that this collection may contain duplicate values.

Since Kotlin 1.0
abstract override val values: MutableCollection<V>

Returns a MutableCollection of all values in this map. Note that this collection may contain duplicate values.

Since Kotlin 1.1

Extensions

Link copied to clipboard
inline fun <K, V, R : Comparable<R>> Map<out K, V>.maxBy(selector: (Map.Entry<K, V>) -> R): Map.Entry<K, V>?
inline fun <K, V, R : Comparable<R>> Map<out K, V>.maxBy(selector: (Map.Entry<K, V>) -> R): Map.Entry<K, V>?
Since Kotlin 1.0
Link copied to clipboard
inline fun <K, V> Map<out K, V>.maxWith(comparator: Comparator<in Map.Entry<K, V>>): Map.Entry<K, V>?
inline fun <K, V> Map<out K, V>.maxWith(comparator: Comparator<in Map.Entry<K, V>>): Map.Entry<K, V>?
Since Kotlin 1.0
Link copied to clipboard
inline fun <K, V, R : Comparable<R>> Map<out K, V>.minBy(selector: (Map.Entry<K, V>) -> R): Map.Entry<K, V>?
inline fun <K, V, R : Comparable<R>> Map<out K, V>.minBy(selector: (Map.Entry<K, V>) -> R): Map.Entry<K, V>?
Since Kotlin 1.0
Link copied to clipboard
fun <K, V> Map<out K, V>.minWith(comparator: Comparator<in Map.Entry<K, V>>): Map.Entry<K, V>?
fun <K, V> Map<out K, V>.minWith(comparator: Comparator<in Map.Entry<K, V>>): Map.Entry<K, V>?
Since Kotlin 1.0
Link copied to clipboard

Converts this Map to a Properties object.

Since Kotlin 1.0
Link copied to clipboard
fun <K : Comparable<K>, V> Map<out K, V>.toSortedMap(): SortedMap<K, V>
fun <K : Comparable<K>, V> Map<out K, V>.toSortedMap(): SortedMap<K, V>

Converts this Map to a SortedMap. The resulting SortedMap determines the equality and order of keys according to their natural sorting order.

Since Kotlin 1.0
fun <K, V> Map<out K, V>.toSortedMap(comparator: Comparator<in K>): SortedMap<K, V>
fun <K, V> Map<out K, V>.toSortedMap(comparator: Comparator<in K>): SortedMap<K, V>

Converts this Map to a SortedMap. The resulting SortedMap determines the equality and order of keys according to the sorting order provided by the given comparator.

Since Kotlin 1.0