mutableMapOf

inline fun <K, V> mutableMapOf(): MutableMap<K, V> (source)

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.*

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>
(source)

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.*

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.*

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
}