January 2018
Intermediate to advanced
434 pages
14h 1m
English
In the following examples, we will try to sort objects based on certain properties. This will give us an idea of how to sort based on the specified comparator:
fun main(args: Array<String>) { val p1=Person(91) val p2=Person(10) val p3=Person(78) val listOfPerson= listOf(p1,p2,p3) var sortedListOfPerson=listOfPerson.sortedBy { it.age }}class Person(var age:Int)
fun main(args: Array<String>) { val p1=Person(91) val p2=Person(10) val p3=Person(78) val listOfPerson= listOf(p1,p2,p3) var sortedListOfPerson=listOfPerson.sortedBy { it.age ...Read now
Unlock full access