Collections工具类
Collections 是一个操作 Set、List 和 Map 等集合的工具类。Collections 中提供了一系列静态的方法对集合元素进行排序、查询和修改等操作,还提供了对集合对象设置不可变、对集合对象实现同步控制等方法。
Modifier and Type | Method | Description |
---|---|---|
static <T> void |
copy(List<? super T> dest, List<? extends T> src) |
Copies all of the elements from one list into another. |
static <T extends Object & Comparable<? super T>>T |
max(Collection<? extends T> coll) |
Returns the maximum element of the given collection, according to the natural ordering of its elements. |
static <T> T |
max(Collection<? extends T> coll, Comparator<? super T> comp) |
Returns the maximum element of the given collection, according to the order induced by the specified comparator. |
static <T extends Object & Comparable<? super T>>T |
min(Collection<? extends T> coll) |
Returns the minimum element of the given collection, according to the natural ordering of its elements. |
static <T> T |
min(Collection<? extends T> coll, Comparator<? super T> comp) |
Returns the minimum element of the given collection, according to the order induced by the specified comparator. |
static void |
reverse(List<?> list) |
Reverses the order of the elements in the specified list. |
static void |
rotate(List<?> list, int distance) |
Rotates the elements in the specified list by the specified distance. |
static void |
shuffle(List<?> list) |
Randomly permutes the specified list using a default source of randomness. |
static void |
shuffle(List<?> list, Random rnd) |
Randomly permute the specified list using the specified source of randomness. |
static <T extends Comparable<? super T>>void |
sort(List<T> list) |
Sorts the specified list into ascending order, according to the natural ordering of its elements. |
static <T> void |
sort(List<T> list, Comparator<? super T> c) |
Sorts the specified list according to the order induced by the specified comparator. |