Using the mutableMapOf() method, we can create a mutable Map(i.e. The Map entries can be changed/replaced).
fun main() {
var x = mutableMapOf(5 to "Is a Number", "John" to "Is a Name", "Kotlin" to "Is a Language")
println(x)
}
So, in the above code we have created a Map using mutableMapOf() method. And the values are represented in Key and Value pairs.
The Key is a number or a String and in the value we have provided its explanation(Somewhat like the English Dictionary).
i.e. We know that the first element 5 is a number. So, in the Key, we have put the number 5 and in its value, we have put the explanation, Is a Number. Same logic is applicable for the other two Keys, John and Kotlin.
A Key and Value is separated by keyword to.
var x = mutableMapOf(5 to "Is a Number", "John" to "Is a Name", "Kotlin" to "Is a Language")
-Function1.png)
And initialised to the variable x.
-Function2.png)
And in the next line we have printed the Map using the print statement.
println(x)
Now, if we see the output,
The output contains Key and Value separated by =.
-Function3.png)
But just remember, while we declare a Map, the Key and Value is separated by keyword to.
-Function4.png)