BigInteger

suggest change

Versions

[{“Name”:“Java SE 1.1”,“GroupName”:null},{“Name”:“Java SE 1.2”,“GroupName”:null},{“Name”:“Java SE 1.3”,“GroupName”:null},{“Name”:“Java SE 1.4”,“GroupName”:null},{“Name”:“Java SE 5”,“GroupName”:null},{“Name”:“Java SE 6”,“GroupName”:null},{“Name”:“Java SE 7”,“GroupName”:null},{“Name”:“Java SE 8”,“GroupName”:null},{“Name”:“Java SE 9 (Early Access)”,“GroupName”:null}]

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 to all of Java’s primitive integer operators, and all relevant methods from java.lang.Math as well as 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 BigInteger implementations should support all integers between -22147483647 and 22147483647 (exclusive). This means BigIntegers can have more than 2 billion bits!

Feedback about page:

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


BigInteger:
* BigInteger

Table Of Contents
8 Arrays
10 Maps
11 Strings
25 JAXB
29 Enums
32 Audio
41 Scanner
58 BigInteger
63 Logging
75 Lists
78 Sets
89 JAX-WS
96 XJC
98 Process
106 Modules
114 Applets
122 JNDI
139 JavaBean
141 Literals
144 Packages
150 JMX
153 JShell
159 Sockets
167 Enum Map
175 Hashtable
177 SortedMap