【发布时间】:2021-02-10 21:06:36
【问题描述】:
我从一个列表中派生出两个独立的组,错误数据和无错误数据:
List<ProductHolder> errorOnes = holderList.stream()
.filter(holder-> (holder.getRecord().isX() || holder.getRecord().isY()))
.collect(Collectors.toList());
List<ProductHolder> nonErrorOnes = holderList.stream()
.filter(holder-> (!holder.getRecord().isX() && !holder.getRecord().isY()))
.collect(Collectors.toList());
上面有多次调用.stream()。
有没有一种方法可以使用对 .stream() 的一次调用将上述内容划分为单独的列表?这样做有性能提升吗?
然后如何访问这些数据?我想我需要使用地图?
【问题讨论】: