我在DVD对象中有一个名为releaseDate
的属性,它是一个String
。
getReleaseDateFormatted()
是我的 DVD 对象中的一种方法,我将在其中解析String
以LocalDate
。
我假设下面的代码会将所有releaseDate
分组到LocalDate
类型中?我需要在此组内找到最新日期。
@Override
public DVDs getOldestDVD() throws PersistenceException {
return dvdMap.values()
.stream()
.collect(Collectors.groupingBy(d -> d getReleaseDateFormatted()))
}
这个问题非常模糊和混乱,但如果我的理解是正确的,你不应该需要任何流。试试这个:
return Collections.max(dvdMap.values(),
Comparator.comparing(DVDs::getReleaseDateFormatted));