java list 排序

//具体的比较类,实现Comparator接口
public class ComparatorUser implements Comparator<User>{

 public int compare(Object arg0, Object arg1) {
  User user0=(User)arg0;
  User user1=(User)arg1;
  return user0.getName().compareTo(user1.getName());
 }
}

//使用Collections的sort方法排序
  ComparatorUser comparator=new ComparatorUser();
  Collections.sort(userlist, comparator);

你可能感兴趣的:(java)