I have list of entities that looks like this:
class History {
public String code;
public Integer version;
public LocalDateTime creationDate;
}
For each code with max version I wanna to get creationDate. I did it like this, but I think that it can be done somehow easier...
Map<String, History> historyMaxVersion = histories.stream()
.collect(Collectors.toMap(History::getCode, Function.identity(),
BinaryOperator.maxBy(Comparator.comparing(History::getVersion))));
Map<String, LocalDateTime> historiesLastUpdatedDates = historyMaxVersion.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue()
.getCreationDate()));