put
Associates the specified value with the specified key in the map.
Since Kotlin
1.0Return
the previous value associated with the key, or null
if the key was not present in the map.
Samples
import kotlin.test.*
import java.util.*
fun main() {
//sampleStart
val map = mutableMapOf(1 to "one", 2 to "two")
map[1] = "*ONE*"
println(map) // {1=*ONE*, 2=two}
map[3] = "tree"
println(map) // {1=*ONE*, 2=two, 3=tree}
println(map.put(3, "three")) // tree
println(map.put(4, "four")) // null
//sampleEnd
}