1
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.

OUT PUT:
BigInteger Value = 1234567890
long Value of BigInteger = 1234567890
int Value of BigInteger = 1234567890
Sponsored Links

1 comments:

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

    ReplyDelete