• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1367
  • Last Modified:

StringTokenizer st=new StringTokenizer(str," -,\t\n\r\f");

st.nexToken(); will get the token from str if available. how to force stringtokenizer to start searching from beginning again?  i don't think such method exist in stringtokenizer. if not, how to destroy the object strintokenizer (own garbage collecting) coz i will be using many stringtokenizer

thank you for your answer .
2 Solutions
zzynxSoftware engineerCommented:
>> i don't think such method exist in stringtokenizer.
Correct afaik

>> how to destroy the object strintokenizer (own garbage collecting) coz i will be using many stringtokenizer
Why bother. The GC should do its job
It will be garbage collected anyway, you needn't worry
You don't have to destroy it by youself, it will be done automatically.
You could set the reference to it to null which would indicate that it is no longer in use, or call System.gc().
It doesn't guarantee that it will be run immediately though.

To start at the beginning, just create a new StringTokenizer (with the same reference if you want).

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

why don't try to use String split function and regex expressions?
do not think Tokenizer is best for your task.
be a bit more precise want yoou want to do want to do with tthe string
One trick could be to always have a stringtokenizer pointing at the beginning... Clone this one when you want to rewind. Javas garbage collector

StringTokenizer stRewind = new StringTokenizer(myString, " ");
StringTokenizer st = stRewind.clone();
while(st.hasMoreTokens()) {
 String myToken = st.nextToken();
 //If you wanna rewind do:


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now