/**
* 把汉字转化为拼音集合
* @param src
* @return Set<String>
*/
public static Set<String> getPinyin(String src) {
if (src != null && !src.trim().equalsIgnoreCase("")) {
char[] srcChar;
srcChar = src.toCharArray();
// 汉语拼音格式输出类
HanyuPinyinOutputFormat hanYuPinOutputFormat = new HanyuPinyinOutputFormat();
// 输出设置,大小写,音标方式等
hanYuPinOutputFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
hanYuPinOutputFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
hanYuPinOutputFormat.setVCharType(HanyuPinyinVCharType.WITH_V);
String[][] temp = new String[src.length()][];
for (int i = 0; i < srcChar.length; i++) {
char c = srcChar[i];
// 是中文或者a-z或者A-Z转换拼音(我的需求,是保留中文或者a-z或者A-Z)
if (String.valueOf(c).matches("[\\u4E00-\\u9FA5]+")) {
try {
temp[i] = PinyinHelper.toHanyuPinyinStringArray(
srcChar[i],
java 实现中文转化为拼音代码 汉字转化为拼音源码分享
最新推荐文章于 2021-02-26 15:28:09 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)