JT White
JT White

Reputation: 517

Easy way to see if an input is an integer?

Is there a simple way to see if an input is an integer in Java?

Upvotes: 0

Views: 1548

Answers (1)

Andrew Marshall
Andrew Marshall

Reputation: 96934

try {
  Integer.parseInt(myString);
} catch(NumberFormatException e) {
  // Not an integer
}

Documentation for parseInt() if you're interested.

Upvotes: 2

Related Questions