If you want to parse an integer consisting of an optional "-" followed by 1 or more decimal digits, then
int num = Integer.parseInt(str);
or
long num = Long.parseLong(str);
If you just want to check and not perform an integer conversion, then regex is another alternative; eg.
boolean ok = Pattern.compile("-?\\d+").matches(str);
Stephen c
source share