public static void main(String[] args) { Apple a = new Apple(); a.setColor("green"); a.setWeight("200"); Apple a2 = new Apple(); a2.setWeight("100"); a2.setColor("green"); Apple a3 = new Apple(); a3.setColor("red"); a3.setWeight("250"); List<Apple> alist = new ArrayList(); alist.add(a); alist.add(a2); alist.add(a3); // 我们对alist进行排序 采用匿名内部类 结合行为参数化(降序) /* alist.sort(new Comparator<Apple>() { public int compare(Apple o1, Apple o2) { return o2.getWeight().compareTo(o1.getWeight()); } });*/ //用lambda表达式就更加简单了 (升序) alist.sort((Apple o1,Apple o2) -> o1.getWeight().compareTo(o2.getWeight())); for (Apple apple : alist) { System.out.println(apple.getClass().toString() + "" + apple.getColor() + apple.getWeight()); } }