How can I add two IntStreams element by element?

Viewed 290

Example;

IntStream a = create(3, 1);  // => [0,0,1]
IntStream b = create(5, 2);  // => [0,0,0,0,2]

The first stream gives an infinite stream of [0,0,1,0,0,1...] and the second an infinite stream of [0,0,0,0,2,0,0,0,0,2,...].

The result stream is ri = ai + bi meaning that I just want to take the sum of the elements at the same position from each stream.

Is this possible in Java ?

2 Answers
Related