HashMap

class HashMap<K, V> : MutableMap<K, V>
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.

class HashMap<K, V> : MutableMap<K, V>
typealias HashMap = HashMap<K, V>

Constructors

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

Constructs an empty HashMap instance.

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

Constructs an empty HashMap instance.

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

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

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

Functions

clear
Link copied to clipboard
Common
open override fun clear()
open override fun clear()
open override fun clear()

Removes all elements from this map.

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

Returns true if the map contains the specified key.

containsValue
Link copied to clipboard
Common
open override fun containsValue(value: @UnsafeVariance V): Boolean
open override fun containsValue(value: V): Boolean
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
JS
open operator override fun equals(other: Any?): Boolean

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

Native
open operator override fun equals(other: Any?): Boolean
get
Link copied to clipboard
Common
open operator override fun get(key: K): V?
open operator override fun get(key: K): V?
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
JS
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
Native
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
JS
open override fun hashCode(): Int

Returns the hash code value for this map.

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

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

Common
open override fun isEmpty(): Boolean
put
Link copied to clipboard
Common
open override fun put(key: K, value: V): V?
open override fun put(key: K, value: V): V?
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
Common
open override fun putAll(from: Map<out K, V>)
Native
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
Common
open override fun remove(key: K): V?
open override fun remove(key: K): V?
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
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
open override val entries: MutableSet<MutableMap.MutableEntry<K, V>>
open override val entries: MutableSet<MutableMap.MutableEntry<K, V>>

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

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
open override val keys: MutableSet<K>
open override val keys: MutableSet<K>

Returns a MutableSet of all keys in this map.

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

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

open override val size: Int

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

values
Link copied to clipboard
open override val values: MutableCollection<V>
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