Java集合:Collection集合操作类
操作集合的工具类:Collecionts
具有一些对集合进行操作的方法
- reverse: 反转
Collections.reverse(list);
- shuffle: 乱序
Collections.shuffle(list);
- sort: 字典升序
可以通过重写实现类中的 Comparator
对List进行排序 Collections.sort(list,Comparator)
Collections.sort(list);
- max: 最大值
可以通过重写实现类中的 Comparator
获得最大值 Collections.max(list,Comparator)
Collections.max(list);
- min: 最小值
可以通过重写实现类中的 Comparator
获得最小值 Collections.min(list,Comparator)
Collections.min(list);
- swap: 交换两个元素
Collections.swap(list,2,1);
-
frequency:获得指定元素的出现次数
-
replaceAll:使用新值替换旧值,替换选中元素的所有值
Collections.replaceAll(list,"a","replace");