这正是
groupingBy收集器允许您执行的操作:
Map<Long, List<Long>> result = values.stream() .collect(Collectors.groupingBy(KeyValue::getKey, Collectors.mapping(KeyValue::getValue, Collectors.toList())));
然后,
mapping收集器将
KeyValue对象转换为它们各自的值。

这正是
groupingBy收集器允许您执行的操作:
Map<Long, List<Long>> result = values.stream() .collect(Collectors.groupingBy(KeyValue::getKey, Collectors.mapping(KeyValue::getValue, Collectors.toList())));
然后,
mapping收集器将
KeyValue对象转换为它们各自的值。