check if string can be parsed to int java code example
Example 1: java check if able to parse int
public static boolean isParsable(String input) {
try {
Integer.parseInt(input);
return true;
} catch (final NumberFormatException e) {
return false;
}
}
Example 2: java check if string is number
try {
int n = Integer.parseInt(str);
} catch (NumberFormatException e) {
// str is not a number
}