Article:
 |
|
Micro-Tuning Step-by-Step
|
| Subject: |
|
Might this not be quicker? |
| Date: |
|
2002-03-26 05:49:54 |
| From: |
|
godfrer
|
|
|
public boolean checkInteger(String testInteger)
{
final int length = testInteger.length();
// since we know that the integer must be
// between 30 and 39999 inclusive, the length
// of the string must be between 2 and 5.
if((length < 2) || (length > 5)) return false;
if(testInteger.charAt(0) != '3') return false;
// no need to actaully calculate the int value
// since we know that it starts with 3 and has
// a length of between 2 and 5. Just need to
// check that all the characters are digits
for(int i = 1; i < length; i++)
if(!Character.isDigit(testInteger.charAt(i)))
return false;
// passed all the tests
return true;
}
|
Showing messages 1 through 1 of 1.
-
RE:Might this not be quicker?
2002-03-29 11:11:48
steveftoth
[View]