James Wierzba :
I am hopeful that it has constant time complexity, but the name implies it is actually counting the tokens.
Jacob G. :
Here's the implementation, if you were curious:
public int countTokens() {
int count = 0;
int currpos = currentPosition;
while (currpos < maxPosition) {
currpos = skipDelimiters(currpos);
if (currpos >= maxPosition)
break;
currpos = scanToken(currpos);
count++;
}
return count;
}
I'm not too familiar with StringTokenizer
, but assuming maxPosition
can change (which it looks like it can), then it's not constant-time. You also have to take into account the complexities of skipDelimiters
and scanToken
.