/**
* 对List<Map>进行排序
*/
private List<Map<String, Object>> OrderBytoList(List<Map<String, Object>> mlist) {
MyComparator mComparator = new MyComparator();
Collections.sort(mlist, mComparator);
return mlist;
}
/**
* 自定义比较器,对List<Map>进行排序*/
private class MyComparator implements Comparator<Map<String, Object>> {
private Collator collator = Collator.getInstance();
@Override
public int compare(Map<String, Object> map1, Map<String, Object> map2) {
// String s1 = (String) map1.get("name");
// String s2 = (String) map2.get("name");
// 把字符串转换为一系列比特,它们可以以比特形式与 CollationKeys 相比较
CollationKey key1 = collator.getCollationKey(map1.get("name").toString());// 用o1.toString().toLowerCase()不区分大小写
CollationKey key2 = collator.getCollationKey(map2.get("name").toString());
return key1.compareTo(key2);// 返回的分别为1,0,-1 分别代表大于,等于,小于。要想按照字母降序排序的话 加个“-”号
}
}