Reversal of a Set can be done using reversed() method. It is independent of the alphabets. And is not a sort. It is just a reversal.
fun main() { var x = mutableSetOf("Mohan", "Kriti", "Salim") var y = x.reversed() println("The Set in reversed order is "+y) }
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,
Then we have used the reversed() Function to reverse the elements of the Set x.
var y = x.reversed()
And the Set x gets sorted in reverse order with Salim as the first value, Mohan second and Kriti as the third.
And we get the below output.
The Set in reversed order is [Salim, Kriti, Mohan]