naturalOrder
Returns a comparator that compares Comparable objects in natural order.
Since Kotlin
1.1Samples
import kotlin.test.*
fun main() {
//sampleStart
val list = listOf("aa", "b", "bb", "a")
val lengthThenNatural = compareBy<String> { it.length }
.then(naturalOrder())
val sorted = list.sortedWith(lengthThenNatural)
println(sorted) // [a, b, aa, bb]
//sampleEnd
}
Returns a comparator that compares Comparable objects in natural order.
Since Kotlin
1.0Samples
import kotlin.test.*
fun main() {
//sampleStart
val list = listOf("aa", "b", "bb", "a")
val lengthThenNatural = compareBy<String> { it.length }
.then(naturalOrder())
val sorted = list.sortedWith(lengthThenNatural)
println(sorted) // [a, b, aa, bb]
//sampleEnd
}