get() method is used to get the value for a particular key.
fun main() { var x = mapOf(5 to "Is a Number", "John" to "Is a Name", "Kotlin" to "Is a Language") var y = x.get("John") println(y) }
So, in the above code we have created a Map and initialised to the variable x.
var x = mapOf(5 to "Is a Number", "John" to "Is a Name", "Kotlin" to "Is a Language")
Now, let us see, how the values are positioned in the Map,
Now, we want to access the value of the key John.
And if we see the value of the key John it is Is a Name.
And the get() method is used to get the value of John.
var y = x.get("John")
And the print statement,
println(y)
Prints the value of y.