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




REMOVE() - FUNCTION


The remove() Function can be used to remove an item from the Map.


Let us say, we want to remove the entry where the Key is 5 and Value is Is a Number.


5, Is a Number


Example :



fun main() {

    var x = mutableMapOf(5 to "Is a Number", "John" to "Is a Name", "Kotlin" to "Is a Language")
    x.remove(5)
    println(x)
}


Output :



  {John=Is a Name, Kotlin=Is a Language}

So, in the above code we have created a Map using mutableMapOf and Key and Value pairs.


var x = mutableMapOf(5 to "Is a Number", "John" to "Is a Name", "Kotlin" to "Is a Language")

And initialised to the variable x.

java_Collections

Now, we are supposed to delete the value of the Key, 5.


So, we have used the below way to update it.


x.remove(5)

And the entry for the Key 5 is deleted for the Map.

java_Collections

And we get the below output,

Output :



  {John=Is a Name, Kotlin=Is a Language}