Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if object is integer

How to determine if Object is Integer? Something like:

if (obj.isInteger()) {...}
like image 694
Klausos Klausos Avatar asked Jan 18 '12 12:01

Klausos Klausos


People also ask

Is object an integer Java?

In Java, integers are not objects and most of the Java utility classes require the use of objects. Thus, if you needed to store an integer in a hashtable, you would have to "wrap" an Integer instance around it. The maximum value an Integer can have.

How do I check if an object is an integer or a string?

The instanceof operator is used to determine if the array item is an Integer or a String . For strings, you must first narrow the Object to string (see line 8 in the source code) and then use the parseInt method of the Integer class (line 9).

How do you check if an object is an integer in Python?

To check if the variable is an integer in Python, we will use isinstance() which will return a boolean value whether a variable is of type integer or not. After writing the above code (python check if the variable is an integer), Ones you will print ” isinstance() “ then the output will appear as a “ True ”.


3 Answers

if (obj instanceof Integer) {....}
like image 57
Aviram Segal Avatar answered Oct 18 '22 11:10

Aviram Segal


if(ob instanceof Integer)

{ your code/logic here}
like image 41
RanRag Avatar answered Oct 18 '22 11:10

RanRag


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

like image 38
KV Prajapati Avatar answered Oct 18 '22 13:10

KV Prajapati