Why does Java’s BigInteger have TEN and ONE as constants? Any Practical use? [closed]

Let’s say you have written a function that returns BigInteger after some calculations and db operations. You often may need to return values like null, 0, 1. It’s easy to return BigInteger.ZERO. This values are public since they are needed commonly.

public BigInteger findMyLovelyBigInteger(Integer secretNumber) {
    if (secretNumber == null) {
        return BigInteger.ZERO; // better than BigInteger.valueOf(0);
    } else {
        // some db operations
    }
}

Also BigInteger.TEN is commonly used for power/divide/mod operations.

Checkout BigInteger public methods. You will easily see their common use cases.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)