?
Solved

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

Posted on 2005-05-11
8
Medium Priority
?
1,344 Views
Last Modified: 2010-05-18
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 .
0
Comment
Question by:second_comet
6 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 100 total points
ID: 13978461
>> 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
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 100 total points
ID: 13978465
It will be garbage collected anyway, you needn't worry
0
 
LVL 9

Expert Comment

by:Nick_72
ID: 13978482
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).

/Nick
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:petmagdy
ID: 13979411
why don't try to use String split function and regex expressions?
0
 
LVL 6

Expert Comment

by:mightyone
ID: 13981244
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
0
 
LVL 2

Expert Comment

by:deadlock_
ID: 14007121
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:
 //st=stRewind.clone();

}

//Jens
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question