引入Maven依賴包web
<!-- https://mvnrepository.com/artifact/com.belerweb/pinyin4j --> <dependency> <groupId>com.belerweb</groupId> <artifactId>pinyin4j</artifactId> <version>2.5.0</version> </dependency>
import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.pinyin4j.format.*; import net.sourceforge.pinyin4j.format.exception.*;
String[] pinyins = PinyinHelper.toHanyuPinyinStringArray("天行健,君子以自強不息。");