问题
i want to sort a list of strings. I know that's not difficult in scala but my problem is, that i need to sort lists in different languages. For example i know that i can sort strings in english very easily. But what's about the russian language or the romanian one? What is the best practice for sorting strings in multiple languages in scala? Does the scala sorting implementation support only english letters?
In java i would do something like this:
Collator coll = Collator.getInstance(locale);
coll.setStrength(Collator.PRIMARY)
Collections.sort(words, coll);
I hope someone out there can help me. Thanks in advance Nico.
回答1:
Nothing different here :). Collator is a comparable, so you convert it to a Ordering
and then use it for sort.
scala> val ord = Ordering.comparatorToOrdering(Collator.getInstance(Locale.FRENCH));
ord: scala.math.Ordering[Object] = scala.math.LowPriorityOrderingImplicits$$anon$7@759fad4
scala> Seq("deux","Bonsoir","Merci").sorted(ord)
res13: Seq[String] = List(Bonsoir, deux, Merci)
来源:https://stackoverflow.com/questions/24860138/sort-list-of-string-with-localization-in-scala