the string tokenizer works with me well in the begining but how can i set the tokenizer to start processing another part if the code. see the code below :
String string = "Mike can not drive ";
.
System.out.println("\nthe token is :\n") ;
StringTokenizer stok = new StringTokenizer(string);
while (stok.hasMoreTokens())
{
System.out.println(stok.nextToken());
}
queue qu = new queue(stok.nextToken().length());
The problem is just with the last code. it seems that no tokens has been read. therfore, is there any method that read the tokens from the begining.
thanks
11-04-2003, 04:50 AM
ArchAngel
You shouldn't really be surprised that there are no tokens left - you've just exited a loop who's exit condition was that there must be no tokens left!
As I see it, you have two choices:
1. Store the number of tokens in the StringTokenizer before you start to iterate over them:
Code:
...
int size = stok.countTokens();
while (stok.hasMoreTokens()) {
System.out.println(stok.nextToken());
}
queue qu = new queue(size);
2. If you're going to be doing more tokenizing, you can just create a new StringTokenizer object:
Code:
...
while (stok.hasMoreTokens()) {
System.out.println(stok.nextToken());
}
stok = new StringTokenizer(string);
queue qu = new queue(stok.countTokens());