How to check if the value is integer in java?

Object x = someApi();

if (x instanceof Integer) 

Note that if someApi() returns type Integer the only possibilities of something returned are:

  • an Integer
  • null

In which case you can:

if (x == null) {
    // not an Integer
} else {
    // yes an Integer
}

Leave a Comment