Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k points)

How can I cast an Object to an int in java?

1 Answer

0 votes
by (46k points)

Assuming the object is an Integer object, then you can do this:

int i = ((Integer) obj).intValue();

If the object isn't an Integer object, then you have to detect the type and convert it based on its type.

Related questions

0 votes
1 answer
asked Aug 7, 2019 in Java by Nigam (4k points)
0 votes
1 answer
asked Aug 6, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
asked Jul 15, 2019 in Java by Nigam (4k points)
0 votes
1 answer
asked Jul 9, 2019 in Java by Nigam (4k points)

Browse Categories

...