package com.bjpowernode.t03sort;
import java.util.ArrayList;
import java.util.Collections;
/*
* 向集合中添加Person类型并对其排序
*/
public class TestSort02 {
public static void main(String[] args) {
ArrayList<Person> list = new ArrayList<>();
list.add(new Person(201,"jack"));
list.add(new Person(301,"abel"));
list.add(new Person(101,"curry"));
list.add(new Person(501,"paul"));
list.add(new Person(801,"kidd"));
list.add(new Person(801,"david"));
//排序前
for(int i=0; i<list.size(); i++) {
System.out.println(list.get(i));
}
//要想对自定义类型进行排序的话,自定义类型需要实现Comparable接口
Collections.sort(list);
System.out.println("================================");
//排序后
for(int i=0; i<list.size(); i++) {
System.out.println(list.get(i));
}
}
}