I have Movie entity as shown below. I need to group all entities by movie code, so implemented as below. Now I need to sort the values of hash map by scan date time in descending order {latest first}. Can I do it during grouping-by process. Here Key is List of Movie entities.
// Movie Entity Model Class
public MovieEntity {
String movieCode;
OffsetDateTime scanDateTime;
String id;
}
// Fetch all movies from other data source.
List<MovieEntity> movieEntities = fetchMovies();
// Convert fetched data by grouping-by movie code
Map<String, List<MovieEntity>> movieResponseEntityMap =
movieEntities
.stream()
.collect(Collectors.groupingBy(MovieEntity::getMovieCode));