|
Sep
08
|
Use static method Integer.parseInt() and catch the exception that is thrown when the number cannot be parsed.
String s = "123";
boolean isValidInteger = false;
try
{
int i = Integer.parseInt(s);
// s is a valid integer
isValidInteger = true;
}
catch (NumberFormatException ex)
{
// s is not an integer
}



Recent Comments