0 votes
1 view
in Java by (10.2k points)

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

1 Answer

0 votes
by (46.1k 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 (4.1k points)
0 votes
1 answer
asked Jul 9, 2019 in Java by Nigam (4.1k 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 (4.1k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...