Collections 是一个操作Set、List 和 Map 等集合的工具类。Collections 中提供了一系列静态的方法对集合元素进行排序、查询和修改等操作,还提供了对集合对象设置不可变、对集合对象实现同步控制等方法。
- reverse(List):反转 List 中元素的顺序
- shuffle(List):对 List集合元素进行随机排序
- sort(List):根据元素的自然顺序对指定List集合元素按升序排序
- sort(List,Comparator):根据指定的Comparator产生的顺序对List集合元素进行排序
- swap(List,int,int):将指定 list 集合中的 i 处元素和 j 处元素进行交换
- Object max(Collection):根据元素的自然顺序,返回给定集合中的最大元素
- Object max(Collection,Comparator):根据 Comparator指定的顺序,返回给定集合中的最大元素
- Object min(Collection):根据元素的自然顺序,返回给定集合中的最小元素
- Object min(Collection,Comparator):根据 Comparator指定的顺序,返回给定集合中的最小元素
- intfrequency(Collection,Object):返回指定集合中指定元素的出现次数
- void copy(List dest,Listsrc):将src中的内容复制到dest中
- boolean replaceAll(Listlist,ObjectoldVal,ObjectnewVal):使用新值替换List对象的所有旧值