Java中文拼音排序工具类

/**
 * 按照拼音排序的工具类
 * @author rxr created at 2008-2-27
 *
 */
public class PinyinComparator implements Comparator {

 public int compare(Object o1, Object o2) {
  String str1 = ((Operator)o1).getOperatorName();
  String str2 = ((Operator)o2).getOperatorName();
  Comparator cmp = Collator.getInstance(java.util.Locale.CHINA);
  return cmp.compare(str1, str2);
 }

}

List list = queryAllOperators();

Collections.sort(list, new PinyinComparator());//按照操作者拼音排序 

你可能感兴趣的:(Java中文拼音排序工具类)