- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Fix for java.math.BigInteger cannot be cast to java.lang.Integer?
You can typecast with the help of method intValue(). The syntax is as follows −
Integer yourVariableName=((BigInteger) yourBigIntegerValue).intValue();
Here is the Java code to convert java.math.BigInteger cast to java.lang.Integer. The code is as follows −
Example
import java.math.BigInteger; public class BigIntegerToInteger { public static void main(String []args) { BigInteger bigValue [] = new BigInteger[5]; bigValue[0] = new BigInteger("6464764"); bigValue[1] = new BigInteger("212112221122"); bigValue[2] = new BigInteger("76475"); bigValue[3] = new BigInteger("94874747"); bigValue[4] = new BigInteger("2635474"); for(int i = 0; i< bigValue.length; i++) { Integer value = ((BigInteger) bigValue[i]).intValue(); System.out.println("Integer value is:"+value); } } }
Here is the sample output −
Output
Integer value is:6464764 Integer value is:1658823618 Integer value is:76475 Integer value is:94874747 Integer value is:2635474
- Related Articles
- Math Operations on BigInteger in Java
- Math operations for BigDecimal in Java
- Multiply one BigInteger to another BigInteger in Java
- Set a bit for BigInteger in Java
- Fix Connectivity error in Java MySQL connection for connector to be set to class path?
- Java multiplyExact() in Math
- Subtract one BigInteger from another BigInteger in Java
- Divide one BigInteger from another BigInteger in Java
- Why constructor cannot be final in Java
- Java lang Integer.toHexString() Method with Examples
- Java lang Long.toOctalString() Method with Examples
- Java Program to check for Integer overflow
- Negate a BigInteger in Java
- BigInteger class in Java\n
- Why a constructor cannot be final in Java?

Advertisements