看来您需要将原始Map的每个值映射到相应的最大MyDayObject:
List allHighest =
weeks.values() // produces a Collection>
.stream() // produces a Stream>
.map(list -> list.stream() // transforms each List to a MyDayObject
// to obtain a Stream
.max((o1, o2) -> o1.value().compareTo(o2.value())).get())
.collect(Collectors.toList()); // collects the elements to a List
附言我只是复制您的代码来查找给定列表的最大元素,而没有尝试对其进行改进,这是可能的.我专注于获得所需的输出.
正如holi-java所评论的,可以简化比较元素的lambda表达式:
List allHighest =
weeks.values()
.stream()
.map(list -> list.stream().max(Comparator.comparing(MyDayObject::value)).get())
.collect(Collectors.toList());