使用Java进行汉字转拼音
经过大量搜索后大致就这四个库
- Pinyin4j
- Jpinyin
- TinyPinyin
- Unidecode
Pinyin4j
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| public class TestPinyin {
@Test public void pinyinConvertBase() { String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray('刘');
for(int i = 0 ; i < pinyinArray.length; ++i ) { System.out.println(pinyinArray[i]); } }
@Test public void pinyinConvertFormat() { HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat(); format.setToneType(HanyuPinyinToneType.WITH_TONE_MARK); format.setVCharType(HanyuPinyinVCharType.WITH_U_UNICODE); format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
String[] pinyin = null;
try { pinyin = PinyinHelper.toHanyuPinyinStringArray('和', format); }catch(BadHanyuPinyinOutputFormatCombination e) { e.printStackTrace(); } for(String py:pinyin) { System.out.println(py); } } }
|
java汉字转拼音开源库piny4j、jpinyin、unidecode小结