Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

Why does BigInteger class has constant TEN and ONE? Any practical uses for having them as constants? I can understand some use cases for ZERO.

like image 932
Harshal Patil Avatar asked Jul 09 '13 09:07

Harshal Patil


People also ask

How many digits can BigInteger hold?

Now that we are able to represent numerical numbers using Strings, we have raised the maximum number we can initialize a big integer to a number with 2147483647 digits. This is because the maximum length of a String is Integer. MAX_VALUE.

How many digits can BigInteger hold in Java?

The BigInteger class allows you to create and manipulate integer numbers of any size. The BigInteger class stores a number as an array of unsigned, 32-bit integer "digits" with a radix, or base, of 4294967296.

What is BigInteger one in Java?

BigInteger provides analogues to all of Java's primitive integer operators, and all relevant methods from java. lang. Math. Additionally, BigInteger provides operations for modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation, and a few other miscellaneous operations.

What is the default value of BigInteger?

The BigInteger specifications don't provide a default constructor like new BigInteger() . Any further suggestion appreciated. If it's actually long , it can't be null . Object references can be null but long is a primitive so it initializes to zero by default.


1 Answers

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.

like image 179
Mustafa Genç Avatar answered Oct 13 '22 06:10

Mustafa Genç