我有一个玩家对象的数组列表。这些选手都有高分。我不知道如何通过数组列表找到得分最高的玩家。collections.sort对此不起作用
public void determineWinner() {
for (int i = 0; i < playersList.size(); i++) {
playersList.get(i).getFrameScores2();
System.out.println("**************");
System.out.println("Player " + playersList.get(i).getName() + " total score is : " + playersList.get(i).getTotalScore());
}
}
1条答案
按热度按时间ycggw6v21#
使用
Collections.max()
以适当的方式Comparator
```Player topScorer = Collections.max(playerList, new Comparator() {
public int compare(Player p1, Player p2) {
return Integer.compare(p1.getTotalScore(), p2.getTotalScore());
}
});