The subtract
method of the BigInteger
class subtracts the passed BigInteger
object value from the called BigInteger
object value.
public BigInteger subtract(BigInteger val)
This method takes a BitInteger
object as an argument.
this - val
This method returns a BitInteger
object. The value of the returned BigInteger
object is the difference between the current BigInteger
object value and the BigInteger
argument’s value.
The example below demonstrates the use of the subtract
method:
import java.math.BigInteger;class BigIntegerSubtractExample {public static void main( String args[] ) {BigInteger val1 = new BigInteger("1000");BigInteger val2 = new BigInteger("100");BigInteger result = val1.subtract(val2);System.out.println(result);}}
In the code above:
BigInteger
class.import java.math.BigInteger;
BigInteger
objects, val1
with the value 1000
and val2
with 100
.BigInteger val1 = new BigInteger("1000");
BigInteger val2 = new BigInteger("100");
subtract
method on the val1
object with val2
as an argument. This method call will return a BigInteger
, which has a value equal to the difference between the val1
and val2
.BigInteger result = val1.subtract(val2); //900