RevorWong
2016-08-06 07:27
采纳率: 100%
浏览 1.6k
已采纳

java中的这个comparator怎么个排序法

import java.util.Comparator;import java.util.TreeSet;public class StudentTreeSet { public static void main(String[] args) { // TODO Auto-generated method stub TreeSet students = new TreeSet(new AgeAscComparator()); students.add(new Student("张三", 3,59)); //实参分别是name,age,score; students.add(new Student("李四", 1,60)); students.add(new Student("王五", 2,88)); students.add(new Student("陈六", 5,46)); students.add(new Student("田七", 4,55)); System.out.println(students); } }class AgeAscComparator implements Comparator{ @Override public int compare(Student o1, Student o2) { return o1.getAge()-o2.getAge(); } }

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题