java 文字转拼音
- 使用工具包 hutool
maven 依赖
<!--hutool工具包--> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.3.5</version> </dependency> <!-- pinyin4j库 --> <dependency> <groupId>com.belerweb</groupId> <artifactId>pinyin4j</artifactId> <version>2.5.1</version> </dependency>
public static void main(String[] args) { String pinyin = PinyinUtil.getPinyin("哈哈哈哈,测试"); System.out.println(pinyin); } 21:11:05.573 [main] DEBUG cn.hutool.log.LogFactory - Use [Slf4j] Logger As Default. 21:11:05.576 [main] DEBUG cn.hutool.extra.pinyin.engine.PinyinFactory - Use [Pinyin4j] Engine As Default. ha ha ha ha ,ceshi Process finished with exit code 0
hutool PinyinUtil 中还有许多其他的静态方法,比如获取首字母之类的,很好用。 pinyin4j 是一个库,供hutool加载。
版权声明:本文为qq_41942909原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。