【发布时间】:2018-03-25 21:27:30
【问题描述】:
我已经用 Boat 对象填充了一个 ArrayList。这艘船有一个名字、一个ID和一个分数。我需要将分数、整数相互比较,然后从低到高排序。
我尝试了很多,也失败了很多,我不知道该怎么做。
public class Boat {
private String name;
private int id;
private int score;
//Constructor
public Boat(String name, int id, int score) {
this.name = name;
this.id = id;
this.score = score;
}
我找到了 Comparator 类,但不知道如何正确使用它。
基本上我需要做的是将分数排序到一个新的 ArrayList 中。按降序将它们从我的private ArrayList<Boat> participants; 列表移到我的private ArrayList<Boat> sortedScoreList; 列表中。
这是我第一次在这里发帖,所以如果我需要添加更多信息,请告诉我。
【问题讨论】:
-
我认为你的问题自相矛盾。你想要降序,还是从最低到最高?
-
我的意思是从最低分到最高分,所以上升......我猜太累了。