Guava学习笔记之排序
来源:互联网 发布:三星平板下载软件 编辑:程序博客网 时间:2024/06/03 17:21
排序器[Ordering]是Guava流畅风格比较器[Comparator]的实现,它可以用来为构建复杂的比较器,以完成集合排序的功能。
从实现上说,Ordering实例就是一个特殊的Comparator实例。Ordering把很多基于Comparator的静态方法(如Collections.max)包装为自己的实例方法(非静态方法),并且提供了链式调用方法,来定制和增强现有的比较器。
创建排序器:
链式调用方法:
运用排序器:
代码:
Ordering<Person> ordering = Ordering.natural() .reverse() .nullsLast() .onResultOf((person) -> { if (person == null) { return null; } return person.getName(); });List<Person> list = new ArrayList<>();list.add(new Person("zhangsan"));list.add(new Person("Lisi"));list.add(null);list.add(new Person("Lisi"));list.add(new Person("wangwu"));List<Person> orderedList = ordering.sortedCopy(list);for (Person person : orderedList) { System.out.println(person);}
结果:
name:zhangsanname:wangwuname:Lisiname:Lisinull
0 0
- Guava学习笔记之排序
- Guava学习笔记:Guava cache
- Guava学习笔记:Guava cache
- Guava学习笔记:Guava cache
- Guava学习笔记:Guava cache
- Guava学习笔记:Guava cache
- Guava学习笔记:Guava cache
- Guava学习笔记:Guava cache
- Guava学习笔记:Guava cache
- Guava学习笔记之Cache实例
- Guava学习笔记:EventBus
- Guava学习笔记:Range
- Guava学习笔记:EventBus
- Guava学习笔记
- Google Guava学习笔记
- Guava学习笔记目录
- Guava学习笔记:EventBus
- Guava学习笔记:Range
- VIM简单配置
- Android学习记录—利用Handler在线程中传递数据
- python定时器
- 僵尸进程是如何产生的?怎样避免僵尸进程的产生
- java琐碎知识点1
- Guava学习笔记之排序
- 解决解决远程连接mysql错误1130
- 【Centos7 GRUB】修改开机等待时间
- MFC中Tab控件的使用详解
- 1020. 月饼 (25)
- java内存管理深入浅出
- Nagios利用NRPE监控Linux主机
- mysql的锁
- Qt 如何处理密集型耗时的事情(频繁调用QApplication::processEvents)