初学Java看到Collections.shuffle(),我说Collection源码里没有这个静态方法啊
细看才发现,工具类Collections多了一个s
1 Collections简介
package java.util包里
- java8 文档原文
This class consists exclusively of static methods that operate on or return collections. It contains polymorphic algorithms that operate on collections, “wrappers”, which return a new collection backed by a specified collection, and a few other odds and ends.- 译文:
此类仅由对集合进行操作或返回集合的静态方法组成。它包含对集合进行操作的多态算法,“包装器”(wrappers)返回由指定集合支持的新集合,以及其他一些零碎的东西。
2 常用方法
方法 | 说明 |
---|---|
void shuffle(List<?> list) | 使用默认随机性对指定的列表元素进行随机重新排序 |
void shuffle(List<?> list, Random random) | 通过使用指定的随机性对列表元素进行随机重新排序来工作 |
void sort(List list) | 默认排序 |
void sort(List list, Comparator<? super T> c) | 根据比较器升序排列 |