BigInteger copying

Carlos Ledesma picture Carlos Ledesma · Jan 8, 2013 · Viewed 8.2k times · Source

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.

Answer

Louis Wasserman picture Louis Wasserman · Jan 8, 2013

BigInteger is immutable -- there should never be any need to copy a BigInteger.