There is a PMD rule saying one should avoid to instantiate BigInteger or BigDecimal if there is a predefined constant.
BigInteger.ZERO
// instead of
new BigInteger(0)
Would there be any other advantage than saving a few bytes?
BigInteger is by far the slowest. Add: BigInt is fastest due to its mutability.
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.
BigInteger is capable of holding far bigger numbers than Long.
The main difference between the BigInteger and BigDecimal is that BigInteger supports arbitrary-precision integers and BigDecimal is for arbitrary-precision fixed-point numbers.
it avoids the allocation of those few bytes and the need to collect them back later
in a tight loop that can matter
Yes, saving a few JVM instructions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With