Java SE API

BigInteger.add()

Return the exact integer sum subject to supported bounds. Java SE API; example uses Java 21-compatible syntax.

Formal Syntax & Structure

java syntaxjava
BigInteger add(BigInteger val)

Parameters & Attributes

NameTypeDescription
valBigIntegerAddend

Return Value

BigInteger

Return the exact integer sum subject to supported bounds.

Working Example

Example Snippetjava
import java.math.*;import java.time.*;import java.time.format.*;import java.time.temporal.*;import java.text.*;import java.util.*;public class Main {    public static void main(String[] args) throws Exception {        BigInteger huge = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);        System.out.println(huge);        try { Math.addExact(Long.MAX_VALUE, 1L); } catch (ArithmeticException ex) { System.out.println("overflow"); }        System.out.println(StrictMath.sqrt(81));        System.out.println(Math.abs(Math.sin(Math.PI)) < 1e-12);    }}
Java Reference