Java add BigInteger

Tags: BigInteger BigInteger add

In this Java core tutorial we learn how to use the method java.math.BigInteger.add() to add two BigInteger values.

How to add two BigInteger values

To add BigInteger value we can use the java.math.BigInteger.add() method which returns the adding result of a BigInteger object and given argument BigInteger object.

AddBigIntegerExample.java

import java.math.BigInteger;

public class AddBigIntegerExample {
    public static void main(String... args) {
        BigInteger value1 = new BigInteger("123456789");
        BigInteger value2 = new BigInteger("987654321");

        BigInteger result = value1.add(value2);

        System.out.println(value1 + " + " + value2 + " = " + result);
    }
}
The output is:
123456789 + 987654321 = 1111111110

Happy Coding 😊