Tuesday 26 March 2013

What is StringTokenizer class?

The StringTokenizer class helps in generating tokens of strings based on a delimiter. The constructor

of StringTokenizer class accepts a string and a delimiter as its input and then splits the supplied string by using the delimiter.



Please note that StringTokenizer class has issues with ASCII characters. So test before relying on this class.

e.g.

import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) {
        StringTokenizer st = new StringTokenizer("abc,def", ",");
        while(st.hasMoreTokens()) {
            System.out.println(st.nextToken());
        }
    }
}
Output:

abc

No comments:

Post a Comment