关于Collections类的一些操作
来源:互联网 发布:网络语言暴力工作视频 编辑:程序博客网 时间:2024/06/04 19:00
直接进入正题吧
1.首先说的是Collections的sort排序操作(list集合也是可以进行排序比较的),max最大值,min最小值操作
List<Integer> list = new ArrayList<Integer>();
list.add(200);
list.add(60);
list.add(300);
System.out.println(Collections.max(list));
System.out.println(Collections.min(list));
Collections.sort(list, new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
// 此处一定要设置为负数不能为0否则达不到预期结果
return o1-o2 > 0 ? 1:-1;
}
});
System.out.println(list);
控制台输出:
300
60
[60, 200, 300]
2.reverse排倒序的方法
List<Integer> list = new ArrayList<Integer>();
list.add(100);
list.add(50);
list.add(500);
System.out.println(Collections.max(list));
System.out.println(Collections.min(list));
Collections.sort(list, new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
// 此处一定要设置为负数不能为0否则达不到预期结果
return o1-o2 > 0 ? 1:-1;
}
});
Collections.reverse(list);
System.out.println(list);
控制台输出:
300
60
[300, 200, 60]
- 关于Collections类的一些操作
- 关于Collections.unmodifiableMap的一些理解
- 类 Collections集合的操作
- 关于类的一些操作
- Collections 操作集合的工具类
- 操作集合的工具类 collections
- 操作集合的工具类:Collections
- 操作集合的工具类:Collections
- Java 操作集合的工具类:Collections
- 操作集合的工具类:Collections
- 操作集合的工具类:collections
- 操作集合的工具类:Collections
- 操作集合的工具类:Collections
- Collections集合操作的工具类
- java中Collections类的常见操作
- 操作集合的工具类Collections
- 操作集合的工具类Collections
- 操作集合的工具类Collections
- android studio 多渠道打包
- windows install mariadb(zip)
- phpStudy刚启动之后Apache就掉线停了
- MySql Host is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts' 解决方法
- tProfiler
- 关于Collections类的一些操作
- Python偶遇Mysql乱码解决方案
- Python2.7和3.5双版本共存和pip的使用
- Mp4文件播放原理分析
- protobuf【1】详细的安装和使用(windows cpp)
- jenkins学习笔记-官网翻译
- 快速排序的Java实现、性能分析以及适用场景
- 快速幂 O(logn)
- Android热修复—阿里的新一代热修复技术Sophix