两个流将 flatMap 设置为整数

The*_*ors 2 java java-stream

final Set<Integer> set1 = new HashSet<>();
final Set<Integer> set2 = new HashSet<>();

Stream.of(set1, set2).mapToInt(???).forEach(intValue -> code)
Run Code Online (Sandbox Code Playgroud)

我有 2 组整数和一个流,但我想将它们全部映射到整数中。我找不到使用 maptoInt 或 flatMap 的方法,因此我可以提取两个集合的所有整数。

Sir*_*nka 5

您可以使用Stream.concat(set1.stream(), set2.stream())which 创建一个新的组合流,以便您可以将您的值映射到 int