核心代码如下:

List<String> result = Stream.of(Lists.newArrayList("A", "B", "C"), Lists.newArrayList("A", "B"))
  .flatMap(Collection::stream).distinct().collect(Collectors.toList());

最终的结果输出是A B C。

应用场景:
有些时候我们需要合并两个返回类型相同的结果集,就可以用这个,不必SQL查询合并结果。

相关文章:

  • 2022-12-23
  • 2021-12-03
  • 2021-12-03
  • 2021-12-03
  • 2021-12-03
猜你喜欢
  • 2022-01-04
  • 2022-01-10
  • 2021-12-06
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案