person对象需要实现comparable接口,并重写compareTo方法

package collection;
import java.util.ArrayList;
import java.util.Collections;
public class TestCollections {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ArrayList<Person> alArrayList=new ArrayList<Person>();
		
		alArrayList.add(new Person("aa", 20));
		
		alArrayList.add(new Person("aa", 18));
		
		alArrayList.add(new Person("aa", 19));
		
		alArrayList.add(new Person("aa", 21));	
		
		//排序 (前提是  person类实现了cpomparator接口)
		Collections.sort(alArrayList);	
		
		Collections.reverse(alArrayList);//倒置
		
		Collections.shuffle(alArrayList);//打乱集合中的数据
		
		System.out.println(alArrayList);
		
		
	}
}                










