实体类: package sort; public class Person { private String name; private int age; public Person(String name, int age) { this.name = name; this.age = 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; } } 比较类: package sort; import java.util.Comparator; public class MyComparator implements Comparator<Person> { @Override public int compare(Person o1, Person o2) { if (o1.getAge() < o2.getAge()) { return 1; } return 0; } } 应用入口: package sort; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class App { public static void main(String[] args) { List<Person> list = new ArrayList<Person>(); list.add(new Person("Li", 23)); list.add(new Person("Wang", 33)); list.add(new Person("Zhang", 28)); Comparator<Person> comp = new MyComparator(); Collections.sort(list, comp); for (Person person : list) { System.out.println(person.getName() + " : " + person.getAge()); } } } 结果: //Wang : 33 //Zhang : 28 //Li : 23