汉字拼音缩写输出工具类

pom文件

<dependency>
    <groupId>com.belerweb</groupId>
    <artifactId>pinyin4j</artifactId>
    <version>2.5.1</version>
</dependency>

工具类

/**
     * 提取每个汉字的首字母
     * 
     * @param str
     *            汉子输入
     * @return String 拼音缩写输出
     */
    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;
    }
原文地址:https://www.cnblogs.com/coder-lzh/p/9455427.html