Using the mapOf() method, we can create an immutable Map(i.e. A read only Map).
fun main() { var x = mapOf(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 mapOf() 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 = mapOf(5 to "Is a Number", "John" to "Is a Name", "Kotlin" to "Is a Language")
And initialised to the variable x.
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 =.
But just remember, while we declare a Map, the Key and Value is separated by keyword to.