이 기사의 예제는 Java 중국어의 특정 코드를 참조를 위해 Pinyin 도구에 공유합니다. 특정 내용은 다음과 같습니다
import com.google.common.base.strings; import net.sourceforge.pinyin4j.pinyinhelper; import net.sourceforge.pinyin4j.format.hanyUpinyInoutPutFormat; import net.sourceforge.pinyin4j.fincat.hanyupinyintontype; import net.sourceforge.pinyin4j.fincat.xception.badhanyUpinyInoutputformatcombination; import org.slf4j.logger; import org.slf4j.loggerfactory; import java.util.arraylist; import java.util.list; import java.util.locale; pinyinutils {private static final logger logger = loggerfactory.getLogger (pinyinutils.class); / ** * 단일 단어 구문 분석 * * @param str first * @return */ public static string [] convert (String str) {String [] reslut = null; hanyUpinyInoutPutFormat hanyUpinyInoutputFormat = new hanyUpinyInoutputformat (); hanyUpinyInoutputformat.settoneType (hanyUpinyIntonEtype.withOut_tone); {reslut = pinyinHelper.toHanyUpinyInstringArray (str.charat (0), hanyUpinyInoutPutFormat); treeset <string> StringTreeset = New Treeset <> (); for (int i = 0; i <reslut.length; i ++) {if (reslut.length> = 3) {break; } stringtreeset.add (reslut [i] .replace ( "u :", "v")); } reslut = new String [StringTreeset.size ()]; Reslut = StringTreeset.ToArray (Reslut); } catch (badhanyUpinyInoutPutformAtCombination badHanyUpinyInoutPutFormatCombination) {badHanyUpinyInoutPutformatCombination.printStackTrace (); } catch (예외 e) {logger.error ( "[convert] :", e); } return reslut; } / ** * 문구 구문 분석 (Full Writing) * * @param chs * @return * / public static string getselling (String chs) {return translate (chs, false); } / ** * 중국어 to pinyin * * @param chs * @param acronym * @return * / private static string translate (String chs, boolean acronym) {StringBuffer buffer = new StringBuffer (); if (strings.isnullorempty (chs)) reto "" "; try {list <list <string >> temps = new ArrayList <> (); int len = chs.length (); int len1 = 0; for (int i = 0; i <len; i ++) {list <string> StringList = new ArrayList <> (); 문자열 키 = chs.charat (i) + ""; if (key.getBytes (). length> = 2) {string [] temp = conver (key); if (temp.length == 0) {계속; } if (temp == null) {stringList.Add ( ""); } else {for (문자열 v : temp) {StringList.add (v); }}} else {stringList.Add (키); } temps.add (StringList); LEN1 ++; } list <list <string >> t = new ArrayList <> (); for (int i = 0; i <len1; i ++) {list <string> currentList = new ArrayList <> (); List <string> StringList = temps.get (i); if (stringList! = null) {for (string s : stringList) {if (aCronym) {s = s.charat (0) + ""; } if (i> 0) {list <string> prelist = t.get (i -1); if (prelist! = null) {for (문자열 s1 : prelist) {currentList.add (s1 + s); }}}} else {currentList.Add (s); }}} t.add (i, currentList); } if (t.size ()> 0) {list <string> currentList = t.get (t.size () -1); if (currentList! = null) {for (string current : currentList) {buffer.append (current); buffer.append ( ""); }}} return buffer.toString (); } catch (예외 e) {logger.error ( "[getSortletters] :", e); 반품 ""; }} / ** * 문구 구문 분석 (약어) * * @param chs * @return * / public static string getSmallselling (String chs) {return translate (chs, true); } / ** * 초기 문자 가져 오기 * * @return * / public static string getSortletters (String Pingyin) {try {String {String SortString = pingyin.subString (0, 1) .toupperCase (locale.getDefault ()); // 첫 번째 문자가 영어 문자인지 여부를 결정하기위한 정규 표현식 (sortstring.matches ( "[az]" ")) {return sortstring.toupperCase (locale.getDefault ()); }} catch (예외 e) {logger.error ( "[getSortletters] :", e); } 반품 "#"; } public static void main (String [] args) {pinyinutils p = new pinyinutils (); System.out.println (p.getselling ( "싱글")); System.out.println (p.getSmallselling ( "test")); }} 위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.