Chinese character conversion Pinyin is a common problem in daily development. For example, if we enter "WH" in the place name of "Great 12306", "Wuhan", "WUHU", and "Weihai", and enter "WUHU", the "WUHU" will appear ". The pinyin4j library can solve this problem well when Java obtains Chinese pinyin characters.: Http://sourceforge.net/projects/pinyin4j/ download unzip, there is a pinyin4j-2.5.0.jar, you can use this library. Conversion of Chinese characters to pinyin: String [] pinyin = PinyinHelper. toHanyuPinyinStringArray ('weight'); The above line of code refers to converting a single Chinese character to pinyin, for example, "heavy". This method returns an array of the String type: "zhong4" "chong2" weight "is a Polyphonic word. The returned array of this method contains all the phonetic alphabet of this word. The last digit in each pronunciation is the tone (the first, the second, the third, and the fourth ). The preceding method is the simplest way to obtain a single Chinese character. You can also use HanyuPinyinOutputFormat to format and return the pinyin format. [Java] HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat (); // UPPERCASE: upper case (ZHONG) // LOWERCASE: lower case (zhong) format. setCaseType (HanyuPinyinCaseType. LOWERCASE); // WITHOUT_TONE: No phonetic symbol (zhong) // WITH_TONE_NUMBER: 1-4 digits to indicate the English logo (zhong4) // WITH_TONE_MARK: directly use the phonetic symbol (WITH_U_UNICODE is required otherwise abnormal) (zh ò ng) format. setToneType (HanyuPinyinToneType. WITH_TONE_MARK); // WITH_V: v represents u (nv) // WITH_U_AND_COLON: u: "represents u (n U :) // WITH_U_UNICODE: directly use u (Nu) www.2cto. comformat. setVCharType (HanyuPinyinVCharType. WITH_U_UNICODE); String [] pinyin = PinyinHelper. toHanyuPinyinStringArray ('weight', format); toHanyuPinyinStringArray returns null if the input character is not a Chinese character and cannot be converted to pinyin. Although pinyin4j is easy to use, it is still limited. The above code can only obtain the Pinyin of a single Chinese character, but cannot obtain the Pinyin of a word that contains multiple words. For example, "chongqing" cannot determine whether it is "chongqing" or "zhongqing", and pinyin4j cannot determine the pronunciation of polyphonic words through context. Therefore, when you obtain the pronunciation of a word that contains multiple words, you can return a list. The correct pronunciation can only be selected manually.