Saturday, July 3, 2010

Java StringTokenizer Example


1. How to use StringTokenizer

package basics;

import java.util.StringTokenizer;

public class StringTokenizerExample {

public static void tokenize(String text) {
StringTokenizer tokenizer = new StringTokenizer(text, "^");
while (tokenizer.hasMoreTokens())
System.out.println(tokenizer.nextToken());
}

public static void main(String[] args) {
StringTokenizerExample.tokenize("AAA^BBB^CCC^DDD");
}
}

The out put will be:
AAA
BBB
CCC
DDD

No comments:

Post a Comment