Maybe I'm really confused because it seems a very simple question but Google and the official documentation were not enough.
I want to copy an BigInteger, and I can't find a clean way of doing it. BigInteger a = b
when b
is a BigInteger, as BigInteger is an object and there's no operator overloading here, a
references to the same object as b
The cleanest way I've found so far is BigInteger a = b.add(BigInteger.ZERO)
, but still a dirty way for me.
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.
Add: BigInt is fastest due to its mutability. Apint is by far the slowest, since it uses a power of 10 base. Sub: The same goes here. Apint is slow when it comes to simple arithmetic operations.
The equivalent of Java long in the context of MySQL variables is BigInt. In Java, the long datatype takes 8 bytes while BigInt also takes the same number of bytes.
BigInteger
is immutable like other wrapper classes such as Integer
and String
. So no worries about possible alteration/tampering.
P.S: As a bonus, here's a link on when defensive copying is needed.
http://www.javapractices.com/topic/TopicAction.do?Id=15
BigInteger
is immutable -- there should never be any need to copy a BigInteger
.
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