Java Hutool 汉字转拼音码

将汉字的首字母转为拼音码,在软件中使用拼音码模糊搜索,用以提示用户的体验感。

一、引入hutool 工具依赖

   <dependency>
           <groupId>cn.hutool</groupId>
           <artifactId>hutool-all</artifactId>
  </dependency>

二、使用工具类提供的转首字母的方法

   public static void main(String[] args) {
        String chinese="zZ中国J阿拉伯";
        String pym= PinyinUtil.getAllFirstLetter(chinese);
        System.out.println(pym);
    }

三、结果

总结:生活是慢慢积累的,技能也是如此,要善用工具类,要解决实际问题用起来就好。

猜你喜欢

转载自blog.csdn.net/chengmin123456789/article/details/107929539