BigInteger

suggest change

Versions

Java SE 1.1 through Java SE 9 (Early Access).

Introduction

The BigInteger class is used for mathematical operations involving large integers with magnitudes too large for primitive data types. For example 100-factorial is 158 digits - much larger than a long can represent. BigInteger provides analogues of Java’s primitive integer operators, the relevant methods from java.lang.Math, and a few other operations.

Syntax

Remarks

BigInteger is immutable. Therefore you can’t change its state. For example, the following won’t work as sum won’t be updated due to immutability.

BigInteger sum = BigInteger.ZERO;
for(int i = 1; i < 5000; i++) {
   sum.add(BigInteger.valueOf(i));  
}

Assign the result to the sum variable to make it work.

sum = sum.add(BigInteger.valueOf(i));

—

The official documentation of BigInteger states that implementations must support every integer from -2^2147483647 exclusive to 2^2147483647 exclusive. A value in that range can use up to 2147483647 bits.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents