我需要根据对象ID从Stream
中筛选出重复项...这是我的try :
private Function<Stream<Person>, Stream<Person>> filterDuplicates() {
return stream -> stream
.collect(
collectingAndThen(
toCollection(() -> new TreeSet<>(comparingLong(Person::getId))),
ArrayList::new))
.stream();
}
因为我还需要Stream
分,能不能把Stream
分过滤到Stream
分而不用中间的ArrayList
分呢?