Java BigInteger intValue() method

The intValue() method of Java BigInteger class is used to convert this BigInteger to a int.This conversion is similar to the narrowing primitive conversion from long to int.

Narrowing Primitive Conversion:

According to The Java Language Specification, it is defined as ifthis BigInteger has too great magnitude to represent as anint, it will return only the lower order 32 bits.

Syntax:

Returns:

This method returns this BigInteger converted to an int.

Note:
  • This method is specified by intValue in class Number.
  • When the return value is finite, this conversion can lose information about the precision of the BigInteger value and return a result with the opposite sign.

Example

Test it Now

Output:

Result of intValue operation on 123 is 123
Result of intValue operation on -123 is -123
Result of intValue operation on 12345678901 is -539222987
Result of intValue operation on -12345678901 is 539222987

Next TopicJava BigInteger




Latest Courses