January 2018
Intermediate to advanced
434 pages
14h 1m
English
We will now see how to sort in descending order using some examples:
val listOfInt= listOf(1,2,3,4,5)var sortedList=listOfInt.sortedDescending()sortedList.forEach { print("${it} ")}
This is the output:
5 4 3 2 1
val p1=Person(91)val p2=Person(10)val p3=Person(78)val listOfPerson= listOf<Person>(p1,p2,p3)val sortedListOfPerson=listOfPerson.sortedByDescending { it.age}sortedListOfPerson.forEach { print("${it.age} ")}
Here's the output:
91 78 10
Read now
Unlock full access