The toSet() method is used to copy one Set to the other creating a read only set.
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]