所以我有一個包含類玩家的陣列串列和一個從建構式創建的物件,引數為玩家(點數,獎杯)。
ArrayList<players> team = new ArrayList<players>();
players player = new players(15,2);
players player2 = new players(15,5);
players player3 = new players(14,8);
team.add(player);
team.add(player2);
team.add(player3);
我想按點數排序,以便首先列印最高點,然后如果點數相同,則按獎杯數對點數相同的點進行排序。我已經嘗試過這樣的集合方法
Collections.sort(team,Comparator.comparingInt(players::getPoints).reversed())
這設法列印出正確的積分順序,但如果積分相同,我無法按獎杯排序。
uj5u.com熱心網友回復:
嘗試這個:
Collections.sort(team, Comparator.comparingInt(players::getPoints).thenComparingInt(players::getTrophies).reverse());
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/373220.html
