public class CollectionsDemo { public static void main(String[] args) { //创建集合对象 List<Integer> list = new ArrayList<Integer>(); //添加元素 list.add(50); list.add(20); list.add(30); list.add(10); list.add(40); //输出集合 System.out.println(list); } }
输出结果:
//public static<T extends Comparable<? super T>> void sort(List<T> list):将指定的列表按升序排序
Collections.sort(list);运行结果:
//public static void reverse(List <?> list):反转指定列表中元素的顺序
Collections.reverse(list);运行结果:
//public static void shuffle(List<?> list):使用默认的随机源随机排列指定的列表
Collections.shuffle(list);运行结果:
第一次:
第二次:
第三次: