Sorting String with non-western characters

前端 未结 6 1770
醉话见心
醉话见心 2020-12-15 01:49

I wanted to print sorted Polish names of all available languages.

import java.util.*;

public class Tmp
{
  public static void main(String... args)
  {
    L         


        
6条回答
  •  粉色の甜心
    2020-12-15 02:19

    You should pass a Collator to the sort method:

    // sort according to default locale
    Collections.sort(langs, Collator.getInstance());
    

    The default sort order is defined by the Unicode codepoints in the string, and that's not the correct alphabetical order in any language.

提交回复
热议问题