本文实例讲述了Java实现的汉语拼音工具类。分享给大家供大家参考,具体如下:
package test;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
public class PingYinUtil {
public static String getAllLeter(String args) {
String result = "";
char[] charArray = args.toCharArray();
String[] strArr = new String[charArray.length];
HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
format.setVCharType(HanyuPinyinVCharType.WITH_V);
int len = charArray.length;
for (int i = 0; i
运行结果:
PS:这里再为大家提供几款本站拼音与字母相关工具供大家参考:
在线中英文根据首字母排序工具:
http://tools.jb51.net/aideddesign/zh_paixu
在线汉字转换成拼音工具:
http://tools.jb51.net/transcoding/pinyin
在线中文汉字转拼音工具:
http://tools.jb51.net/transcoding/hanzi2pinyin
在线中文汉字拼音对照转换工具:
http://tools.jb51.net/transcoding/zh_pinyin
在线字母大小写转换工具:
http://tools.jb51.net/transcoding/upper
附:本例中使用到的net.sourceforge.pinyin4j包可点击此处本站下载pinyin4j的jar包文件。
关于eclipse导入jar包的方法可参考本站https://www.jb51.net/softjc/552873.html
更多关于java相关内容感兴趣的读者可查看本站专题:《Java数组操作技巧总结》、《Java字符与字符串操作技巧总结》、《Java数学运算技巧总结》、《Java数据结构与算法教程》及《Java操作DOM节点技巧总结》
希望本文所述对大家java程序设计有所帮助。



