2

I have a List<BigInteger> and I want to sum its contents. It can be easily done by looping through it.

 List<BigInteger> listOfNumbers = new ArrayList<>();
  //Some code that populates listOfNumbers
  ... 
  BigInteger sum = new BigInteger("0");
  for(BigInteger num : listOfNumbers) {
        sum = sum.add(num);
  }

I was wondering if it was possible to do it using Java 8 streams.

Stefan Zobel
  • 3,182
  • 7
  • 28
  • 38
bisarch
  • 1,388
  • 15
  • 31

0 Answers0