There are two ways by which we can copy one Set to the other.
Let us look at the first way using the toSet() method.
fun main() { val x = mutableSetOf("Mohan", "Kriti", "Salim") var y = x.toSet() println("The Copied Set is "+y) }
So, in the above code we have created a Set and initialised to the variable x.
val x = mutableSetOf("Mohan", "Kriti", "Salim")
Below is how the values are positioned in the Set,
Then we have used the toSet() method and create a new Set that would be the exact copy of x.
Then assign it to y.
var y = x.toSet()
And we get the below output,
The Copied Set is [Mohan, Kriti, Salim]
The toMutableSet() is exactly same as toSet() method. Just that toMutableSet() creates a set that can be changed.