Skip to content

Instantly share code, notes, and snippets.

@mahdi-malv
Created November 10, 2018 08:18
Show Gist options
  • Save mahdi-malv/9e65ae5e0ea0ac99088a8e5ea14ffc9c to your computer and use it in GitHub Desktop.
Save mahdi-malv/9e65ae5e0ea0ac99088a8e5ea14ffc9c to your computer and use it in GitHub Desktop.
Sort objects of the list by an attribute of them.
//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