mutableMapOf

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

Returns an empty new MutableMap.

The returned map preserves the entry iteration order.

Since Kotlin

1.1

Samples

import samples.*
import kotlin.test.*
import java.util.*
fun main() { 
   //sampleStart 
   val map = mutableMapOf<Int, Any?>()
assertTrue(map.isEmpty())

map[1] = "x"
map[2] = 1.05
// Now map contains something:
assertPrints(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.

Samples

import samples.*
import kotlin.test.*
import java.util.*
fun main() { 
   //sampleStart 
   val map = mutableMapOf(1 to "x", 2 to "y", -1 to "zz")
assertPrints(map, "{1=x, 2=y, -1=zz}")

map[1] = "a"
assertPrints(map, "{1=a, 2=y, -1=zz}") 
   //sampleEnd
}
import samples.*
import kotlin.test.*
import java.util.*
fun main() { 
   //sampleStart 
   val map = mutableMapOf<Int, Any?>()
assertTrue(map.isEmpty())

map[1] = "x"
map[2] = 1.05
// Now map contains something:
assertPrints(map, "{1=x, 2=1.05}") 
   //sampleEnd
}