Android 按中文首字母排序

按中文字母排序git

使用https://github.com/belerweb/pinyin4j
github


    /**web

     * 获得中文首字母缩写
     *
     * @param str
     * @return
     */
    public static String getPinYinHeadChar(String str) {

        String convert = "";
        for (int j = 0; j < str.length(); j++) {
            char word = str.charAt(j);
            String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
            if (pinyinArray != null) {
                convert += pinyinArray[0].charAt(0);
            } else {
                convert += word;
            }
        }
        return convert.toUpperCase();

    }ide


public class Demo implements Serializable, Comparable<Demo>{this


    private String sortKey;排序

    public String getSortKey() {
        return sortKey;
    }get


    public void setSortKey(String sortKey) {
        this.sortKey = sortKey;
    }
it

    @Override
    public int compareTo(Demo another) {
        return this.getSortKey().compareTo(another.getSortKey());
    }
class

}
im