Map

interface Map<K, out V>(source)

A 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. Methods in this interface support only read-only access to the map; read-write access is supported through the MutableMap interface.

Since Kotlin

1.0
interface Map<K, out V>(source)

A 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. Methods in this interface support only read-only access to the map; read-write access is supported through the MutableMap interface.

Since Kotlin

1.1

Parameters

K

the type of map keys. The map is invariant in its key type, as it can accept key as a parameter (of containsKey for example) and return it in keys set.

V

the type of map values. The map is covariant in its value type.

K

the type of map keys. The map is invariant in its key type, as it can accept key as a parameter (of containsKey for example) and return it in keys set.

V

the type of map values. The map is covariant in its value type.

Types

Link copied to clipboard
interface Entry<out K, out V>

Represents a key/value pair held by a Map.

Since Kotlin 1.0
interface Entry<out K, out V>

Represents a key/value pair held by a Map.

Since Kotlin 1.1

Functions

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: @UnsafeVariance V): Boolean

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

Since Kotlin 1.0
abstract fun containsValue(value: @UnsafeVariance 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: @UnsafeVariance 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: @UnsafeVariance 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

Properties

Link copied to clipboard
abstract val entries: Set<Map.Entry<K, V>>

Returns a read-only Set of all key/value pairs in this map.

Since Kotlin 1.0
abstract val entries: Set<Map.Entry<K, V>>

Returns a read-only Set of all key/value pairs in this map.

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

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

Since Kotlin 1.0
abstract val keys: Set<K>

Returns a read-only Set 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 val values: Collection<V>

Returns a read-only Collection of all values in this map. Note that this collection may contain duplicate values.

Since Kotlin 1.0
abstract val values: Collection<V>

Returns a read-only Collection of all values in this map. Note that this collection may contain duplicate values.

Since Kotlin 1.1

Inheritors

Link copied to clipboard

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