中文字符串怎么按拼音比较大小(转)

 1 import    java.util.Comparator;     
 2     
 3    public    class    PinYinComparator    implements    Comparator    {     
 4     
 5        public    int    compare(Object    o1,    Object    o2)    {     
 6            try    {     
 7                String    s1=new    String(o1.toString().getBytes("GB2312"),"ISO-8859-1");     
 8                String    s2=new    String(o2.toString().getBytes("GB2312"),"ISO-8859-1");     
 9                return    s1.compareTo(s2);     
10            }     
11            catch    (Exception    e)    {     
12                e.printStackTrace();     
13            }     
14            return    0;     
15        }     
16    }     
17     
18    import    java.util.ArrayList;     
19    import    java.util.Collections;     
20     
21    public    class    Tester    {     
22        public    static    void    main(String[]    args)    {     
23            ArrayList    list=new    ArrayList();     
24            list.add("啊");     
25            list.add("包");     
26            list.add("从");     
27            list.add("随");     
28            list.add("其");     
29            list.add("在");     
30            list.add("平");     
31            list.add("人");     
32            list.add("他");     
33            list.add("以");     
34            list.add("和");     
35            list.add("就");     
36            list.add("可");     
37            list.add("了");     
38            list.add("没");     
39            list.add("额");     
40            list.add("分");     
41            list.add("个");     
42            Collections.sort(list,new    PinYinComparator());     
43            for    (int    i=0;i<list.size();i++)    {     
44                System.out.println(list.get(i));     
45            }     
46        }     
47     
48    }     
==================================================

作者: Panderen

博客: http://panderen.cnblogs.com

签名: 机会总是为有准备的人而准备的!

原文地址:https://www.cnblogs.com/panderen/p/2455026.html