Is there a Kotlin way of locale-specific sorting? ...
# announcements
e
Is there a Kotlin way of locale-specific sorting?
Copy code
fun sort(list: List<String>): List<String> {
    val collator = Collator.getInstance(Locale.GERMAN)
    collator.strength = Collator.PRIMARY
    return list.sortedWith(Comparator {a, b -> collator.compare(a, b)})
}
i
collator is a comparator, so you can just use
sortedWith(collator)
e
Thanks, that’s a bit better. Still Collator is Java-specific, right?
b
It is an API written in Java that is completely accessible from the Kotlin ecosystem
333 Views