1,图示
2,代码
一个条件时
// 获取中文环境
Comparator comparator = Collator.getInstance(Locale.CHINA);
// 排序实现
Collections.sort(list, (e1, e2) -> {
return comparator.compare(e1.get("name"), e2.get("name"));
});
两个条件时
// 获取中文环境
Comparator comparator = Collator.getInstance(Locale.CHINA);
// 排序实现
Collections.sort(list, (e1, e2) -> {
if(comparator.compare(e1.get("name"), e2.get("name"))==0){
return comparator.compare(e1.get("classname"), e2.get("classname"));
}else {
return comparator.compare(e1.get("name"), e2.get("name"));
}
});