6

java 中文排序奇怪的问题如何解决

 2 years ago
source link: https://www.oschina.net/question/2303434_2324035
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

java 中文排序奇怪的问题如何解决

码上中国博客 发布于 昨天 11:46
阅读 143

使用JAVA的排序功能对一个list的字符串进行排序,发现排序出来的结果很奇怪,没有按照想要的排序规则出来:

        List<String> tempList = Lists.newArrayList();
        tempList.add("科雷嘉");
        tempList.add("科雷缤");
        tempList.add("科雷傲");
        tempList.add("科雷缤");
        tempList.add("科雷傲");
        tempList.add("科雷嘉");
        Collections.sort(tempList, Comparator.comparing(e -> e));
        System.out.println("=============================" + tempList);

这段代码排序出来的结果为:

=============================[科雷傲, 科雷傲, 科雷嘉, 科雷嘉, 科雷缤, 科雷缤]

而不是我想要的

=============================[科雷傲, 科雷傲, 科雷缤, 科雷缤, 科雷嘉, 科雷嘉]

请问不转换为拼音的前提下,如何才能做到按照拼音进行排序?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK