AbstractMap

Platform and version requirements: JVM (1.1), JS (1.1), Native (1.1)
abstract class AbstractMap<K, out V> : Map<K, V>

Provides a skeletal implementation of the read-only Map interface.

The implementor is required to implement entries property, which should return read-only set of map entries.

Parameters

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

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

Constructors

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

<init>

Provides a skeletal implementation of the read-only Map interface.

AbstractMap()

Properties

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

keys

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

open val keys: Set<K>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

size

open val size: Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

values

Returns a read-only Collection of all values in this map.

open val values: Collection<V>

Functions

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

containsKey

open fun containsKey(key: K): Boolean
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

containsValue

open fun containsValue(value: V): Boolean
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

equals

Compares this map with other instance with the ordered structural equality.

open fun equals(other: Any?): Boolean
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

get

open operator fun get(key: K): V?
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

hashCode

Returns the hash code value for this map.

open fun hashCode(): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

isEmpty

open fun isEmpty(): Boolean
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

toString

Returns a string representation of the object.

open fun toString(): String

Extension Functions

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

all

Returns true if all entries match the given predicate.

fun <K, V> Map<out K, V>.all(
    predicate: (Entry<K, V>) -> Boolean
): Boolean
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

any

Returns true if map has at least one entry.

fun <K, V> Map<out K, V>.any(): Boolean

Returns true if at least one entry matches the given predicate.

fun <K, V> Map<out K, V>.any(
    predicate: (Entry<K, V>) -> Boolean
): Boolean
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

asIterable

Creates an Iterable instance that wraps the original map returning its entries when being iterated.

fun <K, V> Map<out K, V>.asIterable(): Iterable<Entry<K, V>>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

asSequence

Creates a Sequence instance that wraps the original map returning its entries when being iterated.

fun <K, V> Map<out K, V>.asSequence(): Sequence<Entry<K, V>>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

contains

Checks if the map contains the given key.

operator fun <K, V> Map<out K, V>.contains(key: K): Boolean
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

containsKey

Returns true if the map contains the specified key.

fun <K> Map<out K, *>.containsKey(key: K): Boolean
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

containsValue

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

fun <K, V> Map<K, V>.containsValue(value: V): Boolean
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

count

Returns the number of entries in this map.

fun <K, V> Map<out K, V>.count(): Int

Returns the number of entries matching the given predicate.

fun <K, V> Map<out K, V>.count(
    predicate: (Entry<K, V>) -> Boolean
): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

filter

Returns a new map containing all key-value pairs matching the given predicate.

fun <K, V> Map<out K, V>.filter(
    predicate: (Entry<K, V>) -> Boolean
): Map<K, V>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

filterKeys

Returns a map containing all key-value pairs with keys matching the given predicate.

fun <K, V> Map<out K, V>.filterKeys(
    predicate: (K) -> Boolean
): Map<K, V>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

filterNot

Returns a new map containing all key-value pairs not matching the given predicate.

fun <K, V> Map<out K, V>.filterNot(
    predicate: (Entry<K, V>) -> Boolean
): Map<K, V>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

filterNotTo

Appends all entries not matching the given predicate into the given destination.

fun <K, V, M : MutableMap<in K, in V>> Map<out K, V>.filterNotTo(
    destination: M, 
    predicate: (Entry<K, V>) -> Boolean
): M
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

filterTo

Appends all entries matching the given predicate into the mutable map given as destination parameter.

fun <K, V, M : MutableMap<in K, in V>> Map<out K, V>.filterTo(
    destination: M, 
    predicate: (Entry<K, V>) -> Boolean
): M
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

filterValues

Returns a map containing all key-value pairs with values matching the given predicate.

fun <K, V> Map<out K, V>.filterValues(
    predicate: (V) -> Boolean
): Map<K, V>
Platform and version requirements: JVM (1.5), JS (1.5), Native (1.5)

firstNotNullOf

Returns the first non-null value produced by transform function being applied to entries of this map in iteration order, or throws NoSuchElementException if no non-null value was produced.

fun <K, V, R : Any> Map<out K, V>.firstNotNullOf(
    transform: (Entry<K, V>) -> R?
): R
Platform and version requirements: JVM (1.5), JS (1.5), Native (1.5)

firstNotNullOfOrNull

Returns the first non-null value produced by transform function being applied to entries of this map in iteration order, or null if no non-null value was produced.

fun <K, V, R : Any> Map<out K, V>.firstNotNullOfOrNull(
    transform: (Entry<K, V>) -> R?
): R?
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

flatMap

Returns a single list of all elements yielded from results of transform function being invoked on each entry of original map.

fun <K, V, R> Map<out K, V>.flatMap(
    transform: (Entry<K, V>) -> Iterable<R>
): List<R>
fun <K, V, R> Map<out K, V>.flatMap(
    transform: (Entry<K, V>) -> Sequence<R>
): List<R>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

flatMapTo

Appends all elements yielded from results of transform function being invoked on each entry of original map, to the given destination.

fun <K, V, R, C : MutableCollection<in R>> Map<out K, V>.flatMapTo(
    destination: C, 
    transform: (Entry<K, V>) -> Iterable<R>
): C
fun <K, V, R, C : MutableCollection<in R>> Map<out K, V>.flatMapTo(
    destination: C, 
    transform: (Entry<K, V>) -> Sequence<R>
): C
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

forEach

Performs the given action on each entry.

fun <K, V> Map<out K, V>.forEach(
    action: (Entry<K, V>) -> Unit)
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

get

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

operator fun <K, V> Map<out K, V>.get(key: K): V?
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

getOrElse

Returns the value for the given key, or the result of the defaultValue function if there was no entry for the given key.

fun <K, V> Map<K, V>.getOrElse(
    key: K, 
    defaultValue: () -> V
): V
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

getValue

Returns the value of the property for the given object from this read-only map.

operator fun <V, V1 : V> Map<in String, V>.getValue(
    thisRef: Any?, 
    property: KProperty<*>
): V1

Returns the value for the given key or throws an exception if there is no such key in the map.

fun <K, V> Map<K, V>.getValue(key: K): V
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

ifEmpty

Returns this map if it's not empty or the result of calling defaultValue function if the map is empty.

fun <M, R> M.ifEmpty(
    defaultValue: () -> R
): R where M : Map<*, *>, M : R
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

isNotEmpty

Returns true if this map is not empty.

fun <K, V> Map<out K, V>.isNotEmpty(): Boolean
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

isNullOrEmpty

Returns true if this nullable map is either null or empty.

fun <K, V> Map<out K, V>?.isNullOrEmpty(): Boolean
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

iterator

Returns an Iterator over the entries in the Map.

operator fun <K, V> Map<out K, V>.iterator(): Iterator<Entry<K, V>>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

map

Returns a list containing the results of applying the given transform function to each entry in the original map.

fun <K, V, R> Map<out K, V>.map(
    transform: (Entry<K, V>) -> R
): List<R>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

mapKeys

Returns a new Map with entries having the keys obtained by applying the transform function to each entry in this Map and the values of this map.

fun <K, V, R> Map<out K, V>.mapKeys(
    transform: (Entry<K, V>) -> R
): Map<R, V>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

mapKeysTo

Populates the given destination map with entries having the keys obtained by applying the transform function to each entry in this Map and the values of this map.

fun <K, V, R, M : MutableMap<in R, in V>> Map<out K, V>.mapKeysTo(
    destination: M, 
    transform: (Entry<K, V>) -> R
): M
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

mapNotNull

Returns a list containing only the non-null results of applying the given transform function to each entry in the original map.

fun <K, V, R : Any> Map<out K, V>.mapNotNull(
    transform: (Entry<K, V>) -> R?
): List<R>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

mapNotNullTo

Applies the given transform function to each entry in the original map and appends only the non-null results to the given destination.

fun <K, V, R : Any, C : MutableCollection<in R>> Map<out K, V>.mapNotNullTo(
    destination: C, 
    transform: (Entry<K, V>) -> R?
): C
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

mapTo

Applies the given transform function to each entry of the original map and appends the results to the given destination.

fun <K, V, R, C : MutableCollection<in R>> Map<out K, V>.mapTo(
    destination: C, 
    transform: (Entry<K, V>) -> R
): C
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

mapValues

Returns a new map with entries having the keys of this map and the values obtained by applying the transform function to each entry in this Map.

fun <K, V, R> Map<out K, V>.mapValues(
    transform: (Entry<K, V>) -> R
): Map<K, R>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

mapValuesTo

Populates the given destination map with entries having the keys of this map and the values obtained by applying the transform function to each entry in this Map.

fun <K, V, R, M : MutableMap<in K, in R>> Map<out K, V>.mapValuesTo(
    destination: M, 
    transform: (Entry<K, V>) -> R
): M
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

maxBy

fun <K, V, R : Comparable<R>> Map<out K, V>.maxBy(
    selector: (Entry<K, V>) -> R
): Entry<K, V>?
Platform and version requirements: JVM (1.4), JS (1.4), Native (1.4)

maxByOrNull

Returns the first entry yielding the largest value of the given function or null if there are no entries.

fun <K, V, R : Comparable<R>> Map<out K, V>.maxByOrNull(
    selector: (Entry<K, V>) -> R
): Entry<K, V>?
Platform and version requirements: JVM (1.4), JS (1.4), Native (1.4)

maxOf

Returns the largest value among all values produced by selector function applied to each entry in the map.

fun <K, V> Map<out K, V>.maxOf(
    selector: (Entry<K, V>) -> Double
): Double
fun <K, V> Map<out K, V>.maxOf(
    selector: (Entry<K, V>) -> Float
): Float
fun <K, V, R : Comparable<R>> Map<out K, V>.maxOf(
    selector: (Entry<K, V>) -> R
): R
Platform and version requirements: JVM (1.4), JS (1.4), Native (1.4)

maxOfOrNull

Returns the largest value among all values produced by selector function applied to each entry in the map or null if there are no entries.

fun <K, V> Map<out K, V>.maxOfOrNull(
    selector: (Entry<K, V>) -> Double
): Double?
fun <K, V> Map<out K, V>.maxOfOrNull(
    selector: (Entry<K, V>) -> Float
): Float?
fun <K, V, R : Comparable<R>> Map<out K, V>.maxOfOrNull(
    selector: (Entry<K, V>) -> R
): R?
Platform and version requirements: JVM (1.4), JS (1.4), Native (1.4)

maxOfWith

Returns the largest value according to the provided comparator among all values produced by selector function applied to each entry in the map.

fun <K, V, R> Map<out K, V>.maxOfWith(
    comparator: Comparator<in R>, 
    selector: (Entry<K, V>) -> R
): R
Platform and version requirements: JVM (1.4), JS (1.4), Native (1.4)

maxOfWithOrNull

Returns the largest value according to the provided comparator among all values produced by selector function applied to each entry in the map or null if there are no entries.

fun <K, V, R> Map<out K, V>.maxOfWithOrNull(
    comparator: Comparator<in R>, 
    selector: (Entry<K, V>) -> R
): R?
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

maxWith

fun <K, V> Map<out K, V>.maxWith(
    comparator: Comparator<in Entry<K, V>>
): Entry<K, V>?
Platform and version requirements: JVM (1.4), JS (1.4), Native (1.4)

maxWithOrNull

Returns the first entry having the largest value according to the provided comparator or null if there are no entries.

fun <K, V> Map<out K, V>.maxWithOrNull(
    comparator: Comparator<in Entry<K, V>>
): Entry<K, V>?
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

minBy

fun <K, V, R : Comparable<R>> Map<out K, V>.minBy(
    selector: (Entry<K, V>) -> R
): Entry<K, V>?
Platform and version requirements: JVM (1.4), JS (1.4), Native (1.4)

minByOrNull

Returns the first entry yielding the smallest value of the given function or null if there are no entries.

fun <K, V, R : Comparable<R>> Map<out K, V>.minByOrNull(
    selector: (Entry<K, V>) -> R
): Entry<K, V>?
Platform and version requirements: JVM (1.4), JS (1.4), Native (1.4)

minOf

Returns the smallest value among all values produced by selector function applied to each entry in the map.

fun <K, V> Map<out K, V>.minOf(
    selector: (Entry<K, V>) -> Double
): Double
fun <K, V> Map<out K, V>.minOf(
    selector: (Entry<K, V>) -> Float
): Float
fun <K, V, R : Comparable<R>> Map<out K, V>.minOf(
    selector: (Entry<K, V>) -> R
): R
Platform and version requirements: JVM (1.4), JS (1.4), Native (1.4)

minOfOrNull

Returns the smallest value among all values produced by selector function applied to each entry in the map or null if there are no entries.

fun <K, V> Map<out K, V>.minOfOrNull(
    selector: (Entry<K, V>) -> Double
): Double?
fun <K, V> Map<out K, V>.minOfOrNull(
    selector: (Entry<K, V>) -> Float
): Float?
fun <K, V, R : Comparable<R>> Map<out K, V>.minOfOrNull(
    selector: (Entry<K, V>) -> R
): R?
Platform and version requirements: JVM (1.4), JS (1.4), Native (1.4)

minOfWith

Returns the smallest value according to the provided comparator among all values produced by selector function applied to each entry in the map.

fun <K, V, R> Map<out K, V>.minOfWith(
    comparator: Comparator<in R>, 
    selector: (Entry<K, V>) -> R
): R
Platform and version requirements: JVM (1.4), JS (1.4), Native (1.4)

minOfWithOrNull

Returns the smallest value according to the provided comparator among all values produced by selector function applied to each entry in the map or null if there are no entries.

fun <K, V, R> Map<out K, V>.minOfWithOrNull(
    comparator: Comparator<in R>, 
    selector: (Entry<K, V>) -> R
): R?
Platform and version requirements: JVM (1.1), JS (1.1), Native (1.1)

minus

Returns a map containing all entries of the original map except the entry with the given key.

operator fun <K, V> Map<out K, V>.minus(key: K): Map<K, V>

Returns a map containing all entries of the original map except those entries the keys of which are contained in the given keys collection.

operator fun <K, V> Map<out K, V>.minus(
    keys: Iterable<K>
): Map<K, V>

Returns a map containing all entries of the original map except those entries the keys of which are contained in the given keys array.

operator fun <K, V> Map<out K, V>.minus(
    keys: Array<out K>
): Map<K, V>

Returns a map containing all entries of the original map except those entries the keys of which are contained in the given keys sequence.

operator fun <K, V> Map<out K, V>.minus(
    keys: Sequence<K>
): Map<K, V>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

minWith

fun <K, V> Map<out K, V>.minWith(
    comparator: Comparator<in Entry<K, V>>
): Entry<K, V>?
Platform and version requirements: JVM (1.4), JS (1.4), Native (1.4)

minWithOrNull

Returns the first entry having the smallest value according to the provided comparator or null if there are no entries.

fun <K, V> Map<out K, V>.minWithOrNull(
    comparator: Comparator<in Entry<K, V>>
): Entry<K, V>?
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

none

Returns true if the map has no entries.

fun <K, V> Map<out K, V>.none(): Boolean

Returns true if no entries match the given predicate.

fun <K, V> Map<out K, V>.none(
    predicate: (Entry<K, V>) -> Boolean
): Boolean
Platform and version requirements: JVM (1.1), JS (1.1), Native (1.1)

onEach

Performs the given action on each entry and returns the map itself afterwards.

fun <K, V, M : Map<out K, V>> M.onEach(
    action: (Entry<K, V>) -> Unit
): M
Platform and version requirements: JVM (1.4), JS (1.4), Native (1.4)

onEachIndexed

Performs the given action on each entry, providing sequential index with the entry, and returns the map itself afterwards.

fun <K, V, M : Map<out K, V>> M.onEachIndexed(
    action: (index: Int, Entry<K, V>) -> Unit
): M
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

orEmpty

Returns the Map if its not null, or the empty Map otherwise.

fun <K, V> Map<K, V>?.orEmpty(): Map<K, V>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

plus

Creates a new read-only map by replacing or adding an entry to this map from a given key-value pair.

operator fun <K, V> Map<out K, V>.plus(
    pair: Pair<K, V>
): Map<K, V>

Creates a new read-only map by replacing or adding entries to this map from a given collection of key-value pairs.

operator fun <K, V> Map<out K, V>.plus(
    pairs: Iterable<Pair<K, V>>
): Map<K, V>

Creates a new read-only map by replacing or adding entries to this map from a given array of key-value pairs.

operator fun <K, V> Map<out K, V>.plus(
    pairs: Array<out Pair<K, V>>
): Map<K, V>

Creates a new read-only map by replacing or adding entries to this map from a given sequence of key-value pairs.

operator fun <K, V> Map<out K, V>.plus(
    pairs: Sequence<Pair<K, V>>
): Map<K, V>

Creates a new read-only map by replacing or adding entries to this map from another map.

operator fun <K, V> Map<out K, V>.plus(
    map: Map<out K, V>
): Map<K, V>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

toList

Returns a List containing all key-value pairs.

fun <K, V> Map<out K, V>.toList(): List<Pair<K, V>>
Platform and version requirements: JVM (1.1), JS (1.1), Native (1.1)

toMap

Returns a new read-only map containing all key-value pairs from the original map.

fun <K, V> Map<out K, V>.toMap(): Map<K, V>

Populates and returns the destination mutable map with key-value pairs from the given map.

fun <K, V, M : MutableMap<in K, in V>> Map<out K, V>.toMap(
    destination: M
): M
Platform and version requirements: JVM (1.1), JS (1.1), Native (1.1)

toMutableMap

Returns a new mutable map containing all key-value pairs from the original map.

fun <K, V> Map<out K, V>.toMutableMap(): MutableMap<K, V>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

withDefault

Returns a wrapper of this read-only map, having the implicit default value provided with the specified function defaultValue.

fun <K, V> Map<K, V>.withDefault(
    defaultValue: (key: K) -> V
): Map<K, V>

Inheritors

AbstractMutableMap

Provides a skeletal implementation of the MutableMap interface.

Platform and version requirements:
abstract class AbstractMutableMap<K, V> : MutableMap<K, V>
Platform and version requirements: JVM (1.1)
abstract class AbstractMutableMap<K, V> : 
    MutableMap<K, V>, 
    AbstractMap<K, V>
Platform and version requirements: JS (1.1), Native (1.1)
abstract class AbstractMutableMap<K, V> : 
    AbstractMap<K, V>, 
    MutableMap<K, V>

© 2010–2021 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-abstract-map/index.html