The add method of the BigInteger class can add the passed BigInteger object value with the called BigInteger object value.
public BigInteger add(BigInteger val)
This method takes a BitInteger object as an argument.
This method returns a BitInteger object. The value of the returned BigInteger object is the sum of the argument and the current BigInteger object value.
The example below demonstrates how to use the add method.
import java.math.BigInteger;class BigIntegerAddExample {public static void main( String args[] ) {BigInteger val1 = new BigInteger("1000");BigInteger val2 = new BigInteger("100");BigInteger result = val1.add(val2);System.out.println(result);}}
In the code above, we do the following:
BigInteger class.import java.math.BigInteger;
BigInteger
objects: val1 with value 1000 and val2 with value 100.BigInteger val1 = new BigInteger("1000");
BigInteger val2 = new BigInteger("100");
add method on the val1 object with val2 as an argument.BigInteger which has a value equal to the sum of val1 and val2.BigInteger result = val1.add(val2); //1100