例如:
plants 和houses 两个集合,进行对比过滤,取出plants里和houses不同的部分,并返回。
List<ImprovedSeedPlant> plants = improvedSeedPlantMapper.selectList(spWrapper);
List<StudsheepSheepHouse> houses = houseMapper.selectList(houseWrapper);
List<ImprovedSeedPlant> dataList = new ArrayList<>();
Map<String,StudsheepSheepHouse> resultMap = houses.stream().collect(Collectors.toMap(StudsheepSheepHouse::getHouseNum, Function.identity()));
if (!org.springframework.util.StringUtils.isEmpty(plants)){
for (ImprovedSeedPlant p : plants) {
String key = p.getSheepHouseName();
if(!resultMap.containsKey(key)){
dataList.add(p);
}
}
}
这段代码演示了如何使用Java集合操作,通过Stream API将`ImprovedSeedPlant`集合与`StudsheepSheepHouse`集合进行对比,过滤出不在`houses`集合中的`plants`元素,最终存储到`dataList`中。
454

被折叠的 条评论
为什么被折叠?



