@Override
public int compare(Integer i1, Integer i2) {
int num = i2.compareTo(i1);
return num == 0 ? -1 : num;
}
});
while (true) {
String line = sc.nextLine();
if ("quit".equals(line)) {
break;
}else{
Integer i = Integer.parseInt(line);
ts.add(i);
}
}
for (Integer integer : ts) {
System.out.println(integer);
}
}
}
public int compare(Integer i1, Integer i2) {
int num = i2.compareTo(i1);
return num == 0 ? -1 : num;
}
为什么必须是i2比较i1 才能实现倒序呢