how to sort non-english strings?

蓝咒 提交于 2019-12-05 17:52:44

You use a Collator for that. Collators are Java's way to handle internationalized comparisons.

List<String> mylist = ...;
Locale croatian = new Locale("hr", "HR");
// Put whatever Locale you need as the argument to the getInstance method.
Collator collator = Collator.getInstance(croatian);
Collections.sort(mylist, collator);

Local is not just "language" but also many other conventions. It is possible for the same language to be sorted differently depending on the country or region or convention within the country - that's why a Locale is identified by at most 3 parts: "country", "region" and "variant".

The concept is called collation. You can look up the concept to know more about it. For example, Oracle/Sun has a tutorial about this concept:

https://docs.oracle.com/javase/tutorial/i18n/text/rule.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!