引入依赖
代码语言:xml复制 <dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.3.8</version>
</dependency>
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.1</version>
</dependency>
代码实例
代码语言:java复制import cn.hutool.extra.pinyin.PinyinUtil;
public class test {
public static void main(String[] args) {
String str = "朱重八";
System.out.println(PinyinUtil.getPinyin(str, ""));
System.out.println(PinyinUtil.getFirstLetter(str, "-"));
}
}
问题
对于多音字的处理,不好,比如朱重八就会被翻译成朱zhong八,而不是朱chong八