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




LIST - clear()


The 'clear()' method can be used to remove all the elements from the List.


Example :



fun main() {
    val x = mutableListOf("Mohan", "Kriti", "Salim")
    x.clear()
    println(x)
}   


Output :



 []

So, in the above code we have created a 'List' and initialised to the variable 'x'.


val x = mutableListOf("Mohan", "Kriti", "Salim")

Below is how the values are positioned in the List,


java_Collections

Next, we have used the 'clear()' function that removes all the elements from the List making the List empty.


And we get an empty List as output,


[]