No. You have to make your own like this:
boolean tryParseInt(String value) { try { Integer.parseInt(value); return true; } catch (NumberFormatException e) { return false; } }
... and you can use it like this:
if (tryParseInt(input)) { Integer.parseInt(input);
EDIT (based on @Erk comment)
Something like the following should be better
public int tryParse(String value, int defaultVal) { try { return Integer.parseInt(value); } catch (NumberFormatException e) { return defaultVal; } }
If you overload this with a method with one string parameter, it will be even better, which will allow you to use it with a default value, which is optional.
public int tryParse(String value) { return tryParse(value, 0) }
Woot4Moo Dec 05 2018-11-21T00: 00Z
source share