# BigInteger intValue() Method in Java

The java.math.BigInteger.intValue() converts this BigInteger to an integer value. If the value returned by this function is too big to fit into integer value, then it will return only the low-order 32 bits. Further there is chance that this conversion can loose information about the overall magnitude of the BigInteger value. This method can also return the result with opposite sign.

Syntax:

`public int intValue()`

Returns: The method returns an int value which represents integer value for this BigInteger.

Examples:

```Input: BigInteger1=32145
Output: 32145
Explanation: BigInteger1.intValue()=32145.

Input: BigInteger1=4326516236135
Output: 1484169063
Explanation: BigInteger1.intValue()=1484169063. This BigInteger is too big for
intValue so it is returning lower 32 bit.
```

Example 1:Below programs illustrate intValue() method of BigInteger class

 `// Java program to demonstrate  ` `// intValue() method of BigInteger ` ` `  `import` `java.math.BigInteger; ` ` `  `public` `class` `GFG { ` ` `  `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``// Creating 2 BigInteger objects ` `        ``BigInteger b1, b2; ` ` `  `        ``b1 = ``new` `BigInteger(``"32145"``); ` `        ``b2 = ``new` `BigInteger(``"7613721"``); ` ` `  `        ``// apply intValue() method ` `        ``int` `intValueOfb1 = b1.intValue(); ` `        ``int` `intValueOfb2 = b2.intValue(); ` ` `  `        ``// print intValue ` `        ``System.out.println(``"intValue of "` `                           ``+ b1 + ``" : "` `+ intValueOfb1); ` `        ``System.out.println(``"intValue of "` `                           ``+ b2 + ``" : "` `+ intValueOfb2); ` `    ``} ` `} `

Output:

```intValue of 32145 : 32145
intValue of 7613721 : 7613721
```

Example 2: when return integer is too big for int value.

 `// Java program to demonstrate  ` `// intValue() method of BigInteger ` ` `  `import` `java.math.BigInteger; ` ` `  `public` `class` `GFG { ` ` `  `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``// Creating 2 BigInteger objects ` `        ``BigInteger b1, b2; ` ` `  `        ``b1 = ``new` `BigInteger(``"4326516236135"``); ` `        ``b2 = ``new` `BigInteger(``"251362466336"``); ` ` `  `        ``// apply intValue() method ` `        ``int` `intValueOfb1 = b1.intValue(); ` `        ``int` `intValueOfb2 = b2.intValue(); ` ` `  `        ``// print intValue ` `        ``System.out.println(``"intValue of "` `                           ``+ b1 + ``" : "` `+ intValueOfb1); ` `        ``System.out.println(``"intValue of "` `                           ``+ b2 + ``" : "` `+ intValueOfb2); ` `    ``} ` `} `

Output:

```intValue of 4326516236135 : 1484169063
intValue of 251362466336 : -2040604128
```

Reference:
BigInteger intValue() Docs

Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.