BigInteger longValue() in Java

longValue(): This method is available in java.math.BigInteger class of Java.

Syntax:

long java.math.BigInteger.longValue()

This method converts this BigInteger to long. This conversion is analogous to an arrowing primitive conversion from long to int as defined in The Java Language Specification: if this BigInteger is too big to fit in a long, only the low-order 64 bits are returned.

Returns: this BigInteger converted to long.

For Example:

BigInteger bigInteger = new BigInteger("1234")

bigInteger.longValue() = > It returns 1234.

Approach

Java

import java.math.BigInteger;

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

        BigInteger bigInteger = new BigInteger("1234");
        System.out.println(bigInteger.longValue());
    }
}

Output:

1234

No comments:

Post a Comment