HashMap

expect class HashMap<K, V> : MutableMap<K, V>
actual typealias HashMap = HashMap<K, V>
actual open class HashMap<K, V> : AbstractMutableMap<K, V> , MutableMap<K, V>

Hash table based implementation of the MutableMap interface.

This implementation makes no guarantees regarding the order of enumeration of keys, values and entries collections.

actual class HashMap<K, V> : MutableMap<K, V>

Constructors

HashMap
Link copied to clipboard
expect fun HashMap()
actual fun HashMap()

Constructs an empty HashMap instance.

actual fun HashMap()
HashMap
Link copied to clipboard
expect fun HashMap(initialCapacity: Int)
actual fun HashMap(initialCapacity: Int)
actual fun HashMap(initialCapacity: Int)
HashMap
Link copied to clipboard
expect fun HashMap(initialCapacity: Int, loadFactor: Float = 0.0f)
actual fun HashMap(initialCapacity: Int, loadFactor: Float = 0.0f)

Constructs an empty HashMap instance.

actual fun HashMap(initialCapacity: Int, loadFactor: Float = 0.0f)
HashMap
Link copied to clipboard
expect fun <K, V> HashMap(original: Map<out K, V>)
actual fun <K, V> HashMap(original: Map<out K, V>)

Constructs an instance of HashMap filled with the contents of the specified original map.

actual fun <K, V> HashMap(original: Map<out K, V>)

Functions

clear
Link copied to clipboard
expect open override fun clear()
actual open override fun clear()

Removes all elements from this map.

actual open override fun clear()

Removes all elements from this map.

containsKey
Link copied to clipboard
expect open override fun containsKey(key: K): Boolean
actual open override fun containsKey(key: K): Boolean

Returns true if the map contains the specified key.

actual open override fun containsKey(key: K): Boolean

Returns true if the map contains the specified key.

containsValue
Link copied to clipboard
expect open override fun containsValue(value: @UnsafeVariance V): Boolean
actual open override fun containsValue(value: V): Boolean

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

actual open override fun containsValue(value: V): Boolean

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

equals
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

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

open operator override fun equals(other: Any?): Boolean
get
Link copied to clipboard
expect open operator override fun get(key: K): V?
actual open operator override 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.

actual open operator override 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.

getOrDefault
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
hashCode
Link copied to clipboard
open override fun hashCode(): Int

Returns the hash code value for this map.

open override fun hashCode(): Int
isEmpty
Link copied to clipboard
expect open override fun isEmpty(): Boolean
open override fun isEmpty(): Boolean

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

actual open override fun isEmpty(): Boolean

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

put
Link copied to clipboard
expect open override fun put(key: K, value: V): V?
actual open override fun put(key: K, value: V): V?

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

actual open override fun put(key: K, value: V): V?

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

putAll
Link copied to clipboard
expect open override fun putAll(from: Map<out K, V>)
actual open override fun putAll(from: Map<out K, V>)

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

remove
Link copied to clipboard
expect open override fun remove(key: K): V?
actual open override fun remove(key: K): V?

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

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
actual open override fun remove(key: K): V?

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

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
toString
Link copied to clipboard
open override fun toString(): String
fun toString(entry: Map.Entry<K, V>): String
open override fun toString(): String

Properties

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

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

actual open override val entries: MutableSet<MutableMap.MutableEntry<K, V>>

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

keys
Link copied to clipboard
expect open override val keys: MutableSet<K>
actual open override val keys: MutableSet<K>

Returns a MutableSet of all keys in this map.

size
Link copied to clipboard
expect open override val size: Int
actual open override val size: Int

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

actual open override val size: Int

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

values
Link copied to clipboard
expect open override val values: MutableCollection<V>
actual open override val values: MutableCollection<V>

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

Inheritors

LinkedHashMap
Link copied to clipboard