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
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)
}
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.
-Function1.png)
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.
-Function2.png)
And we get the below output,