Sponsored Links

Ad by Google
In this post we are going to show you, how to convert BigInteger to long, int in java.
java.math.BigInteger is a class extends java.lang.Number class sometimes we used to keep the large value in BigInteger, mostly in database we use BigInteger and corresponding to that BigInteger use long in java class. So here we are going to convert BigInteger to long and int.

Below BigIntegerTest.java class where we are getting long and int value from the BigInteger.

package com.javamakeuse.poc;
import java.math.BigInteger;

public class BigIntegerTest {
 public static void main(String[] args) {

  BigInteger largeValue = new BigInteger("1234567890");

  // getting long value from the BigInteger
  long longValue = largeValue.longValue();

  // getting int value from the BigInteger
  int intValue = largeValue.intValue();

  // printing BigInteger
  System.out.println("BigInteger Value = " + largeValue);
  System.out.println("long Value of BigInteger = " + longValue);
  System.out.println("int Value of BigInteger = " + intValue);

Run BigIntegerTest.java and see the output.

BigInteger Value = 1234567890
long Value of BigInteger = 1234567890
int Value of BigInteger = 1234567890
Sponsored Links


  1. Thank you, I had been looking for some online reference to be used in my Java training and your work really helped me.
    Java J2EE Training in Chennai | Java J2EE Training in Chennai | Java J2EE Training in Chennai

  2. Thanks Rahul, Glade to hear that, it helps you to add into your training reference.