Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   
   RUBY   
   C++   




GET() - FUNCTION


get() method is used to get the value for a particular key.


Example :



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)
}


Output :



  Is a Name

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,

java_Collections

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.

java_Collections

And the get() method is used to get the value of John.


var y = x.get("John")
java_Collections


And the print statement,


println(y)

Prints the value of y.