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());
Bookmarks