# Java常用类之Collections的常用方法 **Repository Path**: fpfgitmy_admin/Java-class-collections ## Basic Information - **Project Name**: Java常用类之Collections的常用方法 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-04-28 - **Last Updated**: 2021-04-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #### Collections工具类的常用方法 | 返回类型 | 方法 | 示意 | 扩展 | 代码示例 | | --- | --- | --- |--- |--- | static void | sort(List list, Comparator c) | 对集合进行定制排序 | -| - | | static int | binarySearch(List> list, T key) | 参数为实现Comparable类的泛型,二分法查找key的索引 | -| - | | static void | reverse(List list) | 反转集合中的元素 | -| - | | static void | shuffle(List list) | 打乱集合中的元素 | -| - | | static void | swap(List list, int i, int j) | 交换集合中位置i和位置j的元素 | -| - | | static | fill(List list, T obj) | 填充集合值为obj | -| - | | static void | copy(List dest, List src) | 资源集合和目标集合大小相同,进行copy | -| - | | static > T | min(Collection coll) | 获取集合中最小值,该集合参数必须继承Comparable类 | -| - | | static > T | max(Collection coll) | 获取集合中最大值,该集合参数必须继承Comparable类 | -| - | | static void | rotate(List list, int distance) | 移动distance个元素的位置,而不改变顺序 | -| - | | static boolean | replaceAll(List list, T oldVal, T newVal) | 替换该集合中oldVal为newVal | -| - | | static Collection | unmodifiableCollection(Collection c) | 返回该集合的镜像,并且镜像不可改变 | -| - | | static Collection | synchronizedCollection(Collection c) | 返回一个线程安全的集合 | -| - | | static Collection | checkedCollection(Collection c,Class type) | 返回给定collection的typesafe视图 | -| - | | static final List | emptyList() | 获取一个空的集合(减少new的代码) | -| - | | static List | singletonList(T o) | 返回一个不可变的集合,调用add会报错 | -| - | | static List | nCopies(int n, T o) | 返回一个添加了n个元素o的集合 | -| - | | static Comparator | reverseOrder() | 获取一个相反(正常顺序:第一个数大于第二个数,相反顺序:第一个数小于第二个数)顺序的比较器 | -| - | | static Enumeration | enumeration(final Collection c) | 将集合转化为枚举 | -| - | | static ArrayList | list(Enumeration e) | Enumeration的ArrayList | -| - | | static int | frequency(Collection c, Object o) | 返回元素o在集合c中出现的次数 | -| - | | static boolean | disjoint(Collection c1, Collection c2) | 集合c1和集合c2中存在公共元素返回false,不存在则true | -| - | | static boolean | addAll(Collection c, T... elements) | 在集合c中添加数组elements) | [关于Collection.addAll和ArrayList.addAll]() | - | | static Set | newSetFromMap(Map map) | 将传入的map转化为泛型为E的Set集合 | -| - | | static Queue | asLifoQueue(Deque deque) | 它返回得就是一个栈形式的队列 | -| - |