Working with BigInteger Values in Java

The java.math.BigInteger class provides operations analogues to all of Java's primitive integer operators and for all relevant methods from java.lang.Math.

BigInteger class is used for big integer calculations which are outside the limit of the primitive data types. It provides operations for modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation, and a few other miscellaneous operations.

The following is an example that displays how we can work with BigInteger values.


 Live Demo

import java.math.BigInteger;
public class BigIntegerDemo {
   public static void main(String[] args) {
      BigInteger bi1, bi2, bi3;
      // assign values to bi1, bi2
      bi1 = new BigInteger("15879");
      bi2 = new BigInteger("87687");
      bi3 = bi1.add(bi2);
      String str = "Addition = " +bi3;;


Addition = 103566
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know