Created
November 10, 2018 08:18
-
-
Save mahdi-malv/9e65ae5e0ea0ac99088a8e5ea14ffc9c to your computer and use it in GitHub Desktop.
Sort objects of the list by an attribute of them.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Sort objects by a value | |
Collections.sort(songList, new Comparator<Song>(){ | |
public int compare(Song a, Song b){ | |
// Here song is a class that has some attrs including title. | |
// We want to sort songs by title | |
return a.getTitle().compareTo(b.getTitle()); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment