Collections工具类详解
1. 介绍
- Collections是一个操作Set, List和Map等集合的工具类
- Collections中提供了一系列静态的方法对集合元素进行排序、查询和修改等操作
2. 排序操作(均为static方法)
- reverse(List):反转List中元素的顺序
- shuffle(List):对List集合中的元素进行随机排序
- sort(List):根据元素的自然顺序对指定List集合元素按顺序排序
- sort(List,Comparator):根据指定的Comparator产生的顺序对List集合元素进行排序
- swap(List, int ,int) :将指定list集合中的i 处元素 和 j 处元素进行交换
3. 查找、替换
- Object max(Collection):根据元素的自然顺序,返回给定集合中的最大元素
- Object max(Collection, Comparator):根据Comparator指定的顺序,返回给定集合中的最大元素
- Object min(Collection)
- Object min(Collection, Comparator)
- int frequency(Collection ,Object):返回指定集合中指定元素出现次数
- void copy(List dest, List src):将src中内容复制到dest中
- boolean replaceAll(List list ,Onject oldVal, Object newVal):使用新值替换List对象的所有旧值
posted @
2021-05-08 16:49
mx_info
阅读(
107)
评论()
收藏
举报