Let us say, we have a Set that contains three names, Mohan, Kriti and Salim. And we want to insert a new name Mika at the end of the Set.
We can use the add() Function without any parameter to achieve the above.
fun main() { var x = mutableSetOf("Mohan", "Kriti", "Salim") x.add("Mika") 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,
Next, we have used the add() function to add the new name Mika at the end of the Set.
x.add("Mika")
And we get the below output,
[Mohan, Kriti, Salim, Mika]