19

How to determine if Object is Integer? Something like:

if (obj.isInteger()) {...}
1
  • other way : if ((Object)(obj).getClass()==Integer.class) {} Commented Apr 8, 2017 at 10:26

3 Answers 3

51
if (obj instanceof Integer) {....}
Sign up to request clarification or add additional context in comments.

Comments

9
if(ob instanceof Integer)

{ your code/logic here}

Comments

5

You may use Class.isInstance() method - This method is the dynamic equivalent of the Java language instanceof operator.

1 Comment

The link is broken. References to newer doc will be in future too I think

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.