How to sort in descending order using multiple comparison fields in Kotlin

You could use the thenByDescending() (or thenBy() for ascending order) extension function to define a secondary Comparator.

Assuming originalItems are of SomeCustomObject, something like this should work:

return ArrayList(originalItems)
        .sortedWith(compareByDescending<SomeCustomObject> { it.localHits }
                .thenByDescending { it.title })

(of course you have to replace SomeCustomObject with your own type for the generic)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)