BigInteger intValue() in Java

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

Syntax:

int java.math.BigInteger.intValue()

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

Returns: this BigInteger converted to an int.

For Example:

BigInteger bigInteger = new BigInteger("1234")

bigInteger.intValue() = > It returns 1234.

Approach

Java

import java.math.BigInteger;

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

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

Output:

1234

No comments:

Post a Comment