https://grokonez.com/kotlin/kotlin-sort-list-objects-kotlin-comparator-example
Kotlin – Sort List of Objects with Kotlin Comparator Example
This tutorial shows you way to Sort List of Objects by implementing Comparator
example.
Related posts:
MyDate(year,month,day)
objects.
Comparator
interface for the class that you use for handling sorting.
- Override compare(object1: T, object2: T)
method and:
+ return zero if object1
is equal object2
+ a negative number if object1
is less than object2
+ a positive number if object1
is greater than object2
- Use sortedWith(comparator: Comparator)
method that returns a List
.
package com.javasampleapproach.objcomparator
data class MyDate (val year: Int, val month: Int, val day: Int) {
}
More at:
https://grokonez.com/kotlin/kotlin-sort-list-objects-kotlin-comparator-example
Kotlin – Sort List of Objects with Kotlin Comparator Example
#kotlin #sort #comparator