根据对象的值进行分类

有一组对象,每一个对象都存储了很多值,

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[],然后再排序,最高分排在第一然后降序。不知道怎么样在一个对象中进行排序,请高手指教。谢谢

使用Arrays.Sort和自定义的Comparator。

public class PlayerScoresComparator implements Comparator<PlayerScores> {
    @Override
    public int compare(PlayerScores lhs, PlayerScores rhs) {
        return lhs.points - rhs.points;
    }
}