Collections 工具类
Collections
介绍
- Collections是一个操作Set、List和Map等集合的工具类
- 提供了一系列静态方法对集合元素进行排序、查询和修改等操作
排序操作(均为static方法)
- reverse(List):反转List中元素
- shuffile(List):对List元素进行随机排序
- sort(List):根据元素的自然排序对指定的List集合元素按升序排序
- sort(List,Comparator):根据指定的Comparator产生的顺序对List集合元素进行排序
- swap(List,int,int):将指定List中的i处与j处元素进行交换
查找替换(均为static方法)
- Object max(Collection):根据元素的自然顺序,返回给定集合中的最大元素
- Object max(Collection,Comparator):Comparator顺序排序,返回最大元素
- Object min(Collection):根据元素的自然顺序,返回给定集合中的最小元素
- Object min(Collection,Comparator):Comparator顺序排序,返回最小元素
- int frequency(Collection,Object):返回指定集合中指定元素的出现次数
- void copy(List dest,List src):将src中的内容复制到dest中
- boolean replaceAll(List list,Object oldVal,Object newVal):使用新值替换List对象中所有旧值
本文详细介绍Java中的Collections工具类,该工具类提供了丰富的静态方法来操作Set、List和Map等集合,包括排序、查询和修改等功能。例如,可以利用sort方法对List进行排序,或者用max方法找出集合中的最大元素。
493

被折叠的 条评论
为什么被折叠?



