Home page

Monday, June 11, 2018

Check if value is integer or not

public static boolean isInteger(String str) {
if (str == null) {
return false;
}
int length = str.length();
if (length == 0) {
return false;
}

for (int i = 0; i < length; i++) {
char c = str.charAt(i);
if (c < '0' || c > '9') {
return false;
}
}
return true;
}

No comments:

Post a Comment