public static void reverse(List<?> list) {}
public static void shuffle(List<?> list) {}
- 根据元素的自然顺序对 List 集合中的元素进行排序:
public static <T extends Comparable<? super T>> void sort(List<T> list) {}
- 根据指定的 Comparator 对 List 集合元素进行排序:
public static <T> void sort(List<T> list, Comparator<? super T> c) {}
public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll) {}
- 根据指定的 Comparator,返回给定集合中的最大元素:
public static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp) {}
public static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> coll) {}
- 根据指定的 Comparator,返回给定集合中的最小元素:
public static <T> T min(Collection<? extends T> coll, Comparator<? super T> comp) {}
public static int frequency(Collection<?> c, Object o) {}
public static <T> void copy(List<? super T> dest, List<? extends T> src) {}
public static <T> boolean replaceAll(List<T> list, T oldVal, T newVal) {}
package com.github.collections.demo1;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* @author maxiaoke.com
* @version 1.0
*/
public class Test {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("aa");
list.add("dd");
list.add("hh");
list.add("bb");
System.out.println("list = " + list); // list = [aa, dd, hh, bb]
Collections.reverse(list);
System.out.println("list = " + list); // list = [bb, hh, dd, aa]
String max = Collections.max(list);
System.out.println("max = " + max); // max = hh
int gg = Collections.binarySearch(list, "gg");
System.out.println("gg = " + gg); // gg = -2
}
}