Java BigInteger.longValue()

Syntax

BigInteger.longValue() has the following syntax.

public long longValue()

Example

In the following code shows how to use BigInteger.longValue() method.


/*from   w  w  w.ja  v a2s. co  m*/
import java.math.BigInteger;

public class Main {

  public static void main(String[] args) {

    BigInteger bi1 = new BigInteger("-123");
    BigInteger bi2 = new BigInteger("987654321");

    // assign the long values of bi1, bi2 to l1, l2
    Long l1 = bi1.longValue();
    Long l2 = bi2.longValue();

    System.out.println(l1);
    System.out.println(l2);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.math »




BigDecimal
BigInteger