inline fun <K, V> mutableMapOf(): MutableMap<K, V>
Platform and version requirements: Kotlin 1.1
Returns an empty new MutableMap.
The returned map preserves the entry iteration order.
import kotlin.test.*
import java.util.*
import kotlin.comparisons.*
fun main(args: Array<String>) {
//sampleStart
val map = mutableMapOf<Int, Any?>()
println("map.isEmpty() is ${map.isEmpty()}") // true
map[1] = "x"
map[2] = 1.05
// Now map contains something:
println(map) // {1=x, 2=1.05}
//sampleEnd
}
fun <K, V> mutableMapOf( vararg pairs: Pair<K, V> ): MutableMap<K, V>
Returns a new MutableMap with the specified contents, given as a list of pairs where the first component is the key and the second is the value. If multiple pairs have the same key, the resulting map will contain the value from the last of those pairs. Entries of the map are iterated in the order they were specified.
import kotlin.test.*
import java.util.*
import kotlin.comparisons.*
fun main(args: Array<String>) {
//sampleStart
val map = mutableMapOf(1 to "x", 2 to "y", -1 to "zz")
println(map) // {1=x, 2=y, -1=zz}
map[1] = "a"
println(map) // {1=a, 2=y, -1=zz}
//sampleEnd
}
import kotlin.test.*
import java.util.*
import kotlin.comparisons.*
fun main(args: Array<String>) {
//sampleStart
val map = mutableMapOf<Int, Any?>()
println("map.isEmpty() is ${map.isEmpty()}") // true
map[1] = "x"
map[2] = 1.05
// Now map contains something:
println(map) // {1=x, 2=1.05}
//sampleEnd
}
© 2010–2017 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/mutable-map-of.html