public static <T> void sort(List<T> list)
排序-示列代码:
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
public class Demo1_collectios {
public static void main(String[] args) {
ArrayList<String> list=new ArrayList<>();
list.add("d");
list.add("a");
list.add("b");
list.add("c");
System.out.println(list);
Collections.sort(list);
System.out.println(list);
}
}
运行结果:
[d, a, b, c]
[a, c, d, b]
public static <T> int binarySearch(List<?> list,T key)
二分查找-示列代码:
ArrayList<String> list=new ArrayList<>();
list.add("a");
list.add("c");
list.add("d");
list.add("f");
list.add("g");
System.out.println(Collections.binarySearch(list,"a"));
运行结果:
1
public static <T> T max(Collection<?> coll)
最大值-示列代码:
ArrayList<String> list=new ArrayList<>();
list.add("a");
list.add("c");
list.add("d");
list.add("f");
list.add("g");
System.out.println(Collections.max(list));
运行结果:
g
public static void reverse(List<?> list)
反转-示列代码:
ArrayList<String> list=new ArrayList<>();
list.add("a");
list.add("c");
list.add("d");
list.add("f");
list.add("g");
Collections.reverse(list);
System.out.print(list);
运行结果:
[g, f, d, c, a]
public static void shuffle(List<?> list)
随机排序-示列代码:
ArrayList<String> list=new ArrayList<>();
list.add("a");
list.add("c");
list.add("d");
list.add("f");
list.add("g");
Collections.shuffle(list);
System.out.print(list);
运行结果:
[f, c, a, g, d]