有一个列表,里面是GraphicItem对象,还有一个是名称的集合set,
现在想过滤掉list里面的对象,只要set中有, list里面就不要
List<GraphicItem> graphicItemList = list.stream()
.filter(graphicItem -> !set.contains(graphicItem.getGraphicId()))
.collect(Collectors.toList());
graphicItemList.forEach(graphicItem -> data.add(graphicItem.getGraphicName()));
过滤列表中指定项

本文介绍了一种使用Java Stream API过滤列表中特定元素的方法。通过一个具体的示例,展示了如何从GraphicItem对象列表中移除那些ID存在于指定集合set中的对象,并收集剩余对象的名称。

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



