Java Stream digits to number

Viewed 1426

I am struggling to get a functioning code for this. I have a stream of digits between 0 and 9. I want to get a BigInteger out of those digits. Example:

IntStream digits = IntStream.of(1, 2, 3) // should get me a Biginteger 123.
IntStream digits = IntStream.of(9, 5, 3) // should get me a Biginteger 953.

Is there a way to concatenate all elements out of the stream? Here is my basic idea:

digits.forEach(element -> result=result.concat(result, element.toString()));
4 Answers
Related