1,List<Map<String,Object>>格式

这种排序方式有bug,如果item.get(sortField)是数字,toString()之后排序是不正确的

//排序
Comparator<Map<String, Object>> comparator = Comparator.comparing(item -> item.get(sortField).toString());
if (Constant.SORT_TYPE_ASC == sortType){
//升序
resourceList.sort(comparator);
}else {
resourceList.sort(comparator.reversed());
}

2,List<Model>格式

resultList.sort(Comparator.comparing(MetaDataModel::getOrder));
dictVoList.sort(Comparator.comparingInt(DictVo::getOrder));

3,Set<Model>格式

public static void test2(){
Set<Student> students = new HashSet<>();
Student student1 = new Student(1,"李四",1);
Student student2 = new Student(2,"张三",3);
Student student3 = new Student(3,"王麻",2);
students.add(student1);
students.add(student2);
students.add(student3);
List<Student> studentList1 = new ArrayList<>(students);
studentList1.sort(Comparator.comparing(Student::getAge));
System.out.println(studentList1);
}

4,Set<String>格式

public static void test3(){
Set<String> sets = new HashSet<>();
sets.add("aa");
sets.add("ee");
sets.add("cc");
//倒序
Set<String> treeSetDesc = new TreeSet<>((o1, o2) -> o2.compareTo(o1));
treeSetDesc.addAll(sets);
System.out.println(treeSetDesc);
//升序
Set<String> treeSetAsc = new TreeSet<>((o1, o2) -> o1.compareTo(o2));
treeSetAsc.addAll(sets);
System.out.println(treeSetAsc);
}

最新文章

  1. awk删除文件第一列
  2. Python语法一
  3. db2常用函数(1)
  4. C++面向过程解决三阶行列式问题
  5. OSGi之Bundle
  6. JDBC连接MySQL数据库及演示样例
  7. .net Remoting 的工作原理是什么?
  8. 将16进制颜色转换成UIColor-ios
  9. 03-python3.5-模拟购物车流程--更新追加细节注释功能
  10. 导入到eclipse里的工程挺大的,然后就一直报: An internal error occurred during: &quot;Building workspace&quot;. GC overhead limit exceeded 这个错误。
  11. Hackergame 2018的一道题目confused_flxg失败心得体会
  12. redis:list列表类型的操作
  13. hisi 生产固件生成
  14. IO流_演示键盘录入
  15. SRS用例
  16. 52.tableViewCell重用机制避免重复显示问题
  17. Selenium+Python自动化测试环境搭建和搭建过程遇到的问题解决
  18. 大数据时代快速SQL引擎-Impala
  19. MySQL 四种链接
  20. vscode新建html,没有模板

热门文章

  1. 【爬坑】DataNode 无法正常启动解决方案
  2. SqlBulkCopy批量添加
  3. [java基础]一文理解java多线程必备的sychronized关键字,从此不再混淆!
  4. [php] yii debug设置
  5. 2个Excel表格核对技巧
  6. Spark远程调试参数
  7. QT数据类型
  8. 20175310 《Java程序设计》第3周学习总结
  9. 学习Karma+Jasmine+istanbul+webpack自动化单元测试
  10. ubuntu打开windows下txt文档乱码问题的解决