您的比较器如下所示:
public class GraduationCeremonyComparator implements Comparator<GraduationCeremony> { public int compare(GraduationCeremony o1, GraduationCeremony o2) { int value1 = o1.campus.compareTo(o2.campus); if (value1 == 0) { int value2 = o1.faculty.compareTo(o2.faculty); if (value2 == 0) { return o1.building.compareTo(o2.building); } else { return value2; } } return value1; }}
基本上,只要到目前为止已比较的属性相等(
== 0),它就会继续比较类的每个连续属性。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)