有一組對象,每一個對象都存儲了很多值,class PlayerScores {
String playerName;
int pos=0;
int played=0;
int win=0;
int draw=0;
int lose=0;
int goalsFor=0;
int goalsAgainst=0;
int goalDifference=0;
int points=0;
public PlayerScores() {
}
}這些都保存在數組中。Player Scores[] playersObjects = new PlayerScores[int];
playersObjects[i] = new PlayerScores();我需要新建一個對象數組,進行搜索playersObject[],然后再排序,最高分排在第一然后降序。不知道怎么樣在一個對象中進行排序,請高手指教。謝謝
1 回答

阿波羅的戰車
TA貢獻1862條經驗 獲得超6個贊
使用Arrays.Sort和自定義的Comparator。
public class PlayerScoresComparator implements Comparator<PlayerScores> { @Override public int compare(PlayerScores lhs, PlayerScores rhs) { return lhs.points - rhs.points; } }
添加回答
舉報
0/150
提交
取消