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;
    }

 

相关文章:

  • 2021-05-26
  • 2022-12-23
  • 2021-08-31
  • 2021-08-25
  • 2022-12-23
  • 2021-08-18
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-18
  • 2022-02-07
  • 2021-08-11
相关资源
相似解决方案