The remove() method to remove an element from the Set by its name/value
Let us say, we have a Set that contains three names, Mohan, Kriti and Salim. And we want to remove Kriti from the Set.
It can be done with the remove() Function
fun main() {
var x = mutableSetOf("Mohan", "Kriti", "Salim")
x.remove("Kriti")
println(x)
}
So, in the above code we have created a Set and initialised to the variable x.
var x = mutableSetOf("Mohan", "Kriti", "Salim")Below is how the values are positioned in the Set,
-Function1.png)
Next, we have used the remove() function that searches for the name Kriti and removes it from the Set.
x.remove("Kriti")-Function2.png)
And we get the below output,
[Mohan, Salim]