The addAll() method is used to join two Sets.
fun main() { var x = mutableSetOf("Mohan", "Kriti", "Salim") var y = mutableSetOf("Sia", "Andrew") x.addAll(y) 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,
Also we have another Set that contains, Sia and Andrew.
var y = mutableSetOf("Sia", "Andrew")
Next, we have used the addAll() function to add the new Set y that contains Sia and Andrew at the end of the Set x.
x.addAll(y)
And the Set y is joined with x.
And we get the below output,
[Mohan, Kriti, Salim, Sia, Andrew]