code: 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;
      }
docs: Calculates the number of times that this tokenizer's
  <code>nextToken</code> method can be called before it generates an
  exception. The current position is not advanced.
  
  @return  the number of tokens remaining in the string using the current
  delimiter set.
  @see     java.util.StringTokenizer#nextToken()