January 2018
Intermediate to advanced
434 pages
14h 1m
English
Now, let's follow these steps to sort a list, while keeping null objects at the end:
class Person(var age:Int?)
val listOfPersons=listOf(Person(10), Person(20), Person(2), Person(null))
val sortedList=listOfPersons.sortedWith(compareBy(nullsLast<Int>(),{it.age}))sortedList.forEach { print(" ${it.age} ")}
The output is as follows:
2 10 20 null
Read now
Unlock full access