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,
-Function1.png)
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.
-Function2.png)
And the get() method is used to get the value of John.
var y = x.get("John")-Function3.png)
And the print statement,
println(y)
Prints the value of y.