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




CLEAR() - FUNCTION


The clear() Function can be used to remove all the elements from the Map.


Example :



fun main() {

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


Output :



  {}

So, in the above code we have created a Map using braces {} 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

And we have used the clear() method to remove all the elements from the 'Map'.


x.clear()

And the print statement, prints an empty Map.

Output :



  {}