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;
}
}
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;
}
}
how to check if parsing in integer is possible in java
// if parse is possible then it will do it otherwise compiler
// will throw exceptions and it is a bad practice to catch all exceptions
// in this case only NumberFormatException happens
public boolean isInteger(String string) {
try {
Integer.valueOf(string);
// Integer.parse(string) /// it can also be used
return true;
} catch (NumberFormatException e) {
return false;
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us