How to cast an Object to an int?

494    Asked by RickiGriffen in Devops , Asked on Jul 18, 2021

How can I cast an Object to int in java?

Answered by Noah Brown

 Assuming the object is an Integer object, then to cast an object to int 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.



Your Answer

Interviews

Parent Categories