You can use flatMapto create IntStreamcontaining 3 elements for each of the elements of the original IntStream:
System.out.println(Arrays.toString(IntStream.range(0, 10)
.flatMap(x -> IntStream.of(x, x*x, -x))
.toArray()));
Conclusion:
[0, 0, 0, 1, 1, -1, 2, 4, -2, 3, 9, -3, 4, 16, -4, 5, 25, -5, 6, 36, -6, 7, 49, -7, 8, 64, -8, 9, 81, -9]
source
share