List<Supply> supplies = iSupplyService.oldAll(supply);
ArrayList<Object> list = new ArrayList<>();
/*//过滤type为1的数据
List<Supply> collect = supplies.stream()
.filter(a -> a.getType()==1)
.collect(Collectors.toList());
list.addAll(collect);
//过滤type为2的数据
List<Supply> collect1 = supplies.stream()
.filter(a -> a.getType()==2)
.collect(Collectors.toList());
list.addAll(collect1);*/
筛选数据为1和2的数据
于 2023-04-21 17:48:07 首次发布
该代码段展示了如何使用Java8的StreamAPI从List<Supply>中过滤出type为1和2的元素,并将它们添加到一个新的ArrayList中。首先,通过iSupplyService的老方法oldAll获取供应列表,然后通过两次stream().filter().collect()操作分别过滤type为1和2的Supply对象,最后将结果合并到list中。





