Java – how to initialize BigInteger after creating an instance (constructor cannot be called)
Imagine an instance of BigInteger, so how do you initialize it after you create it?
For example:
BigInteger t = new BigInteger();
How do I put a value in t?
If the constructor cannot be called, what can be done to put the value in the object?
Solution
I'm not 100% sure what exactly confuses you, because you will initialize the items in the BigInteger array, just like other object arrays For example,
BigInteger t2 [] = new BigInteger[2]; t2[0] = new BigInteger("2"); t2[1] = BigInteger.ZERO; // ZERO,ONE,and TEN are defined by constants // or BigInteger[] t3 = {new BigInteger("2"),BigInteger.ZERO};
Editor 1: ah, now I understand your problem: you want to create a BigInteger instance and then set its value The answer is the same as strings: you can't, and this is because BigIntegers likes that strings are immutable and can't be changed once created For this reason, this class does not have a "setter" method The way to change the BigInteger variable value is to set it to a new BigInteger instance