原文地址:https://blog.csdn.net/weixin_41751625/article/details/79735271
在实际生活中,我们经常会用到根据中文拼音的首字母进行排序。从而方便进行检索汉字,例如一个公司的人员,按照姓名的拼音的首字母进行排序,这种场景很多。
我自己写了一个简单的实现这种排序的代码,仅供大家参考。
public class TestCompare { private static Comparator comparator=Collator.getInstance(java.util.Locale.CHINA); public static void main(String[] args) { List<String> personList=Arrays.asList("帮大幅度","安大幅度","大地方","层 浮点"); Collections.sort(personList,comparator); System.out.println(personList); } }
输出结果为
[安大幅度, 帮大幅度, 层 浮点, 大地方]
很明显的看的出来,已经进行排序了。