在实际生活中,咱们常常会用到根据中文拼音的首字母进行排序。从而方便进行检索汉字,例如一个公司的人员,按照姓名的拼音的首字母进行排序,这种场景不少。java
我本身写了一个简单的实现这种排序的代码,仅供你们参考。code
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); } }
输出结果为排序
[安大幅度, 帮大幅度, 层 浮点, 大地方]很明显的看的出来,已经进行排序了。