BigInteger objects are immutable. Their values ββcannot be changed after creation.
When you call .add , a new BigInteger object is created and returned, and must be saved if you want to access its value.
BigInteger total = BigInteger.ZERO; total = total.add(fiveThousand); total = total.add(fiftyThousand); total = total.add(fiveHundredThousand); System.out.println(total);
(Itβs good to say total = total.add(...) , because it simply removes the link to the old total object and reassigns it to the new one created by .add ).
source share