Collections类概述:是针对集合操作的工具类
Collections类的常用方法:
1、public static
2、public static void reverse(List<?>list); 反转指定列表中元素的顺序;
3、public static void shuffle(List<?>list); 使用默认的随机源随机排列指定列表;
package day42;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.List;public class CollectionsDemo01 { public static void main(String[] args) { //创建集合对象 List
示例: 对array进行排序(需要重写compare方法)
代码如下
package day42;public class Student { private String name; private int age; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public Student(){} public Student(String name, int age){ this.name = name; this.age = age; }}package day42;import java.lang.reflect.Array;import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;public class CollectionsDemo02 { public static void main(String[] args) { ArrayList