package com.utils;
import java.text.Collator;
import java.util.Comparator;
import java.util.Locale;
/**
* java中汉字排序
* @author 花非花雾非雾
*/
public class MyComparator implements Comparator {
public int compare(Object arg0, Object arg1) {
//参数量示例:[花非花, 2012-12-3]
String[] temp0 = (String[]) arg0;
String[] temp1 = (String[]) arg1;
int flag = Collator.getInstance(Locale.CHINESE).compare(temp0[0],temp1[0]);
if (flag == 0) {
return Collator.getInstance(Locale.CHINESE).compare(temp0[2],temp1[2]);
} else {
return flag;
}
}
public static void main(String[] args) {
Collections.sort(list, new MyComparator());
}
}
java中汉字排序
最新推荐文章于 2022-11-01 14:33:20 发布