java中汉字按拼音排序
import java.util.Comparator;
class PinYinComparator implements Comparator<String> {
public int compare(String s1, String s2) {
return ((java.text.RuleBasedCollator)java.text.Collator.
getInstance(java.util.Locale.CHINA)).compare(s1, s2);
}
}
但是在GWT中不支持java.text...
改成这样
new Comparator<Object>() {
@Override
public int compare(Object o1, Object o2) {
return javascriptSort(o1, o2);
}
private native int javascriptSort(Object a, Object b)/*-{
return a.localeCompare(b);
}-*/;
}
没有评论:
发表评论