I'm looping through BigInteger
like this:
BigInteger i = new BigInteger(Long.MAX_VALUE + "");
BigInteger end = i.add(new BigInteger("10"));
// Display results
for (i = new BigInteger(Long.MAX_VALUE + "");
i.compareTo(end) <= 0;
i = i.add(new BigInteger("1"))) {
System.out.println(i.multiply(i));
}
And that's too expensive due memory usage, because of creating new BigInteger
object every loop instead of just increment the value using ++
.
Is there a way to increment the value instead of creating new object every time?