The put() method is used to insert a new element(i.e. A Key Value pair) in the Map.
fun main() { var x = mutableMapOf(5 to "Is a Number", "John" to "Is a Name", "Kotlin" to "Is a Language") x.put("Rose", "Is a Flower") println(x) }
So, in the above code we have created a Map using mutableMapOf() and Key and Value pairs.
var x = mutableMapOf(5 to "Is a Number", "John" to "Is a Name", "Kotlin" to "Is a Language")
And initialised to the variable x.
Now, we are supposed to add a new entry to the Map. Where the Key would be Rose and the Value Is a Flower.
So, we have used the put() method to add it.
x.put("Rose", "Is a Flower")
And the entry is added to the Map.
And we get the below output,