Reputation:
In the conversion from int to BigInteger, we write
int n = 100;
BigInteger bi = BigInteger.valueOf(n);
when we print bi, we get 100. but, in the conversion from String to BigInteger, we write
String str = "100";
BigInteger biStr = new BigInteger(str);
biStr
object uses the new
keyword to store the value of the BigInteger value that is converted from a string, but where will the bi
object store its BigInteger value that is converted from int.
Upvotes: 0
Views: 45
Reputation: 4592
Quoting the BigInteger javadoc for valueOf:
"This "static factory method" is provided in preference to a (long) constructor because it allows for reuse of frequently used BigIntegers."
Upvotes: 1