Collections工具类介绍

  1. Collections是一个操作Set、 List和Map等集合的工具类
  2. Collections中提供了一系列静态的方法对集合元素进行排序、查询和修改等操作

排序操作:(均为static方法)

  1. reverse(List): 反转List中元素的顺序
  2. shuffle(List): 对List集合元素进行随机排序
  3. sort(List): 根据元素的自然顺序对指定List集合元素按升序排序 也可以sort(Listm Comparator)按指定比较器产生的顺序来排序
  4. swap(List, int, int): 将指定list集合中的i处元素与j处元素交换

查找、替换

  1. Object max(Collection) :根据元素自然顺序,返回给定集合中最大元素
  2. Object max(Collection, Comparator)
  3. Object min
  4. int frequency(Collection, Object):返回集合中指定元素的出现次数
  5. void copy(List dest, List src): src中内容复制到dest
  6. boolean replaceAll(List list, Object oldVal, Object newVal): 使用新值替换List对象的所有旧值

本文章使用limfx的vscode插件快速发布