我有一个叫classes
类谁拥有这个compareTo方法:使用compareTo方法
@Override
public int compareTo(Object other) {
Cours ot = (Cours)other;
String heure2 = ot.heure;
int autre = Integer.parseInt(heure2.substring(0,2));
int le = Integer.parseInt(this.heure.substring(0,2));
if (autre > le) {
return 1;
}
if (autre == le) {
return 0;
} else {
return -1;
}
}
我还有一个叫day
类,它具有的classes
列表:
private List<Cours> journee;
而且一分类方法:
public void TrieListe() {
Collections.sort(journee);
}
当我使用TrieListe()
一切正常,我可以排序列表。
但我也添加了Weeks
另一个类,它包含的Days
列表,现在我想从该类使用TrieList():
private List<Days> leWeek;
public void TrieListe() {
Collections.sort(leWeek);
}
那么,怎样才能用我compareTo
方法从我classes
在我的Weeks
类中使用sort()的类。
你确定要使用相同的compareTo方法?你的“周”课有一个叫“heure”的成员? – RubioRic
http://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#sort-java.util.List-java.util.Comparator-也许 –
我想比较每一天使用在类中的“heure”属性因此,按“heure”排序 – yoyani