Kotlin Sort Object List with Kotlin Selector function – crossinline selector: (T) -> R?
In the tutorial, JavaSampleApproach will show you how to Sort Kotlin Object List with Kotlin Selector function - crossinline selector: (T) -> R?
Related posts:
- Sort List of Objects with Kotlin Comparator Example
- Sort List of Objects with Kotlin Comparable
- Kotlin Binary Search for Object List with Comparison function – comparison: (T) -> Int
- Kotlin Binary Search for Object List with Selector function – crossinline selector: (T) -> K?
I. Technologies
– Java 1.8
– Kotlin 1.1.61
II. Kotlin Sort Object List with Selector
We have sortedBy(crossinline selector: (T) -> R?)
for ascending sorted list, and sortedByDescending(crossinline selector: (T) -> R?)
for descending sorted list.
- Method signature of
sortedBy(crossinline selector: (T) -> R?)
public inline fun > Iterable.sortedBy(crossinline selector: (T) -> R?): List
- Method signature of
sortedByDescending(crossinline selector: (T) -> R?)
public inline fun > Iterable.sortedByDescending(crossinline selector: (T) -> R?): List
So We need define an appropriate selector function for them.
-> Step to do:
- Create data model
- Create selector function
- Do Sorting
More at:
Kotlin Sort Object List with Kotlin Selector function – crossinline selector: (T) -> R?
Top comments (0)