1public static boolean isParsable(String input) {
2 try {
3 Integer.parseInt(input);
4 return true;
5 } catch (final NumberFormatException e) {
6 return false;
7 }
8}
1// if parse is possible then it will do it otherwise compiler
2// will throw exceptions and it is a bad practice to catch all exceptions
3// in this case only NumberFormatException happens
4public boolean isInteger(String string) {
5 try {
6 Integer.valueOf(string);
7 // Integer.parse(string) /// it can also be used
8 return true;
9 } catch (NumberFormatException e) {
10 return false;
11 }
12}
13