怎么对List中的对象进行排序

如何对List中的对象进行排序最近研究了一下对list中的对象进行排序,以前还真不知道可以这么搞.首先,需要排

如何对List中的对象进行排序
最近研究了一下对list中的对象进行排序,以前还真不知道可以这么搞.
首先,需要排序的对象需要实现Comparable接口.这个接口需要实现的方法名是public int compareTo(比较对象). 这个方法返回三种状态,大于0的int,等于0的int ,小于0的int.  当当前对象大于比较对象的时候返回大于0的int,以此类推:

List personList<Person>=getPersonList();Collections.sort(personList);

1 楼 spiritfrog 2008-03-28   不是这样吧,list本身就是无序的。
应该用Comparator,Collections.sort(personList, comparator);  2 楼 darkjune 2008-03-28   恩,是这样的,我为了方便直接实现comparable接口