The clear() Function can be used to remove all the elements from the Map.
fun main() {
var x = mutableMapOf(5 to "Is a Number", "John" to "Is a Name", "Kotlin" to "Is a Language")
x.clear()
println(x)
}
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.
-Function1.png)
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.