addAll 添加另一集合里面的元素
add 添加整个集合包括 []

stream流方法

两个list合并并去重
@Test
public void testCollect2Lists(){
List<String> result = Stream.of(Lists.newArrayList("A", "B", "C"), Lists.newArrayList("A", "B"))
.flatMap(Collection::stream).distinct().collect(Collectors.toList());
log.info(result.toString());
}
本文介绍了如何使用Java 8的Stream API将两个List合并,并通过flatMap、distinct和collect方法实现去重。通过示例展示了如何运用`addAll`操作添加另一个集合的元素。

8120

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



