Home Segments Top Top Previous Next

489: Mainline

You can think of a tokenizer as though it were a machine that steps through a stream of tokens. The nextToken method moves the machine from one token to the next. Suppose, for example, that you call nextToken with tokens, a StreamTokenizer instance, as the target:

tokens.nextToken() 

The first time that Java executes a call to the nextToken method, given that the first token is a number, the value of that token is assigned to the nval instance variable in the tokenizer:

 *-- First token                       *-----------* 
 |                                     | tokens    | 
 |                                     |  nval: 4  | 
 v                                     *-----------* 
--- 
 4       7       3       8       8       ... 

After Java executes the second call to nextToken, the second token is assigned to nval:

         *-- Second token              *-----------* 
         |                             | tokens    | 
         |                             |  nval: 7  | 
         v                             *-----------* 
        --- 
 4       7       3       8       8       ...