Home »
Java »
Java Reference »
Java BigInteger Class
Java BigInteger Class | intValue() Method with Example
BigInteger Class intValue() method: Here, we are going to learn about the intValue() method of BigInteger Class with its syntax and example.
Submitted by Preeti Jain, on May 10, 2020
BigInteger Class intValue() method
- intValue() method is available in java.math package.
- intValue() method is used to convert this BigInteger into an integer and when this BigInteger value is large enough to fit in an int so lower order 32 bits are to be retrieved with the reverse sign.
- intValue() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
- intValue() method does not throw an exception at the time of representing an integer.
Syntax:
public int intValue();
Parameter(s):
Return value:
The return type of this method is int, it returns the conversion value of this BigInteger into an integer.
Example:
// Java program to demonstrate the example
// of int intValue() method of BigInteger
import java.math.*;
public class IntValueOfBI {
public static void main(String args[]) {
// Initialize two variables str1 and str2
String str1 = "80231245";
String str2 = "1001245";
// Initialize two BigInteger objects
BigInteger b_int1 = new BigInteger(str1);
BigInteger b_int2 = new BigInteger(str2);
// converts this BigInteger (b_int1) into
// an int, and store the result in a variable
// named i_conv
int i_conv = b_int1.intValue();
System.out.println("b_int1: " + b_int1);
System.out.println("b_int1.intValue(): " + i_conv);
System.out.println();
// converts this BigInteger (b_int2) into
// an int, and store the result in a variable
// named i_conv
i_conv = b_int2.intValue();
System.out.println("b_int2: " + b_int2);
System.out.println("b_int2.intValue(): " + i_conv);
}
}
Output
b_int1: 80231245
b_int1.intValue(): 80231245
b_int2: 1001245
b_int2.intValue(): 1001245