如何在哈希映射中获取包含最新 LocalDate 的对象



我在DVD对象中有一个名为releaseDate的属性,它是一个String

getReleaseDateFormatted()是我的 DVD 对象中的一种方法,我将在其中解析StringLocalDate

我假设下面的代码会将所有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));

最新更新