Returns true if all characters in string s are numbers. Accepts non-signed integers only. Does not accept floating point, exponential notation, etc.
(String s)
| 303 | * point, exponential notation, etc. |
| 304 | */ |
| 305 | public static boolean isInteger(String s) { |
| 306 | if (isEmpty(s)) return defaultEmptyOK; |
| 307 | |
| 308 | // Search through string's characters one by one |
| 309 | // until we find a non-numeric character. |
| 310 | // When we do, return false; if we don't, return true. |
| 311 | for (int i = 0; i < s.length(); i++) { |
| 312 | // Check that current character is number. |
| 313 | char c = s.charAt(i); |
| 314 | |
| 315 | if (!isDigit(c)) return false; |
| 316 | } |
| 317 | |
| 318 | // All characters are numbers. |
| 319 | return true; |
| 320 | } |
| 321 | |
| 322 | /** Returns true if all characters are numbers; |
| 323 | * first character is allowed to be + or - as well. |
no test coverage detected