Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Jenya Mia
Added: Mar 19, 2019 12:38 PM
Views: 15
Tags: list sort
  1. /**
  2.  * Returns a sorted version of the provided List of Songs that is
  3.  * sorted first by year of song's release, then sorted by artist,
  4.  * and then sorted by album.
  5.  *
  6.  * @param songsToSort Songs to be sorted.
  7.  * @return Songs sorted, in this order, by year, artist, and album.
  8.  */
  9. private static List < Song > sortedSongsByYearArtistAlbum(final List < Song > songsToSort)
  10. {
  11.     return songsToSort.stream()
  12.         .sorted(
  13.             Comparator.comparingInt(Song::getYear)
  14.             .thenComparing(Song::getArtist)
  15.             .thenComparing(Song::getAlbum))
  16.         .collect(Collectors.toList());
  17. }