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

Posted on 2005-05-11
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 .
Question by:second_comet
    LVL 37

    Accepted Solution

    >> 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
    LVL 86

    Assisted Solution

    It will be garbage collected anyway, you needn't worry
    LVL 9

    Expert Comment

    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).

    LVL 13

    Expert Comment

    why don't try to use String split function and regex expressions?
    LVL 6

    Expert Comment

    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
    LVL 2

    Expert Comment

    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:



    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

    732 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now