在Java中使用Collator类按照汉字拼音排序字符串

public static void main(String[] args) throws Exception{
        String[] strs = new String[]{"张","王","李"};
        Arrays.sort(strs,Collator.getInstance(Locale.CHINA));
        for (int i = 0; i < strs.length; i++) {
            System.out.println(strs[i]);
        }
    }

李
王
张

不过,该排序方法并不能对所有中文精确排序,如果仅仅涉及到常用的中文,可以通过这种方式排序

相关文章:

  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2021-09-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-15
相关资源
相似解决方案