The 'sort()' Function is used to sort a List in Ascending order.
fun main() { val x = mutableListOf("Mohan", "Kriti", "Salim") x.sort() println("The Sorted List in ascending 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 'sort()' method to sort the List 'x' in ascending order.
And the List 'x' gets sorted with 'Kriti' as the first value, 'Mohan' second and 'Salim' as the third.
And we get the below output.
fun main() { val x = mutableListOf(5, 3, 2, 4) x.sort() println("The Sorted List in increasing 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 'sort()' method to sort the List 'x' in increasing order.
And the numbers in the List 'x' gets sorted.
And we get the below output.