How do I convert a String to a BigInteger?
BigInteger has a constructor where you can pass string as an argument.
try below,
private void sum(String newNumber) {
// BigInteger is immutable, reassign the variable:
this.sum = this.sum.add(new BigInteger(newNumber));
}
According to the documentation:
BigInteger(String val)
Translates the decimal String representation of a BigInteger into a BigInteger.
It means that you can use a String
to initialize a BigInteger
object, as shown in the following snippet:
sum = sum.add(new BigInteger(newNumber));
Using the constructor
BigInteger(String val)
Translates the decimal String representation of a BigInteger into a BigInteger.
Javadoc