sortDescending() is used to sort a List in Descending order.
The 'sortDescending()' Function is used to sort a List in Descending order.
fun main() { val x = mutableListOf("Mohan", "Kriti", "Salim") x.sortDescending() println("The Sorted List in descending order is "+x) }
So, in the above code we have created a 'List' and initialised to the variable 'x'.
Below is how the values are positioned in the List,
Then we have used the parameter 'reverse = True' along with the 'sort()' method to sort the List 'x' in descending order.
And the List 'x' gets sorted in descending order with 'Salim' as the first value, 'Mohan' second and 'Kriti' as the third.
And we get the below output.
Next let us see, how to sort a List in Descending order.
fun main() { val x = mutableListOf(5, 3, 2, 4) x.sortDescending() println("The Sorted List in decreasing order is "+x) }
So, in the above code we have created a 'List' and initialised to the variable 'x'.
Below is how the values are positioned in the List,
Then we have used the parameter 'reverse = True' along with the 'sort()' method to sort the List 'x' in decreasing order.
And the List 'x' gets sorted in decreasing order.
And we get the below output.