Jump to content

Sort using a custom comparator: Difference between revisions

m
Line 2,263:
 
<lang kotlin>fun main(args: Array<String>) {
val strings = listOf("Here", "are", "some", "sample", "strings", "to", "be", "sorted")
println("Unsorted: $strings")
 
val sorted = strings.map { Triple (it, it.length, it.lowercase()) }.sortedWith (
kotlin.Comparator { a, b ->
compareValues(b.second, a.second).let {
if (it == 0) compareValues(a.third, b.third)
else it
}
}
}).map { it.first }
 
println("Sorted: $sorted")
}
</lang>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.