Sorting ObservableList<Class> by value in ascending and descending order - JAVAFX

Viewed 17916

I have a Class which has playerName and Score, I have created a ObservableList of this class in my Controller class. Players and scores are added to this array. But the question is how do I sort it according to the score?

ObservableList<PlayerScore> playerScores = FXCollections.observableArrayList();

This is how it looks so far:

//stateACS is a toggle button
if (stateASC.isSelected()) {
    //Sort in asc order by player score
    FXCollections.sort(playerScores);
}else{
    //sort in desc order by player score

}
2 Answers
Related