The following is another program on "StringTokenizer Tokenizing String" that takes a group of delimiters supplied explicitly.
import java.util.StringTokenizer;
public class STDemo2
{
public static void main(String args[])
{
String str1 = "Awake@arise*stop/notmuntil@goal*reach";
StringTokenizer st1 = new StringTokenizer(str1, "@,m,*,/");
System.out.println("Number of tokens in str1: " + st1.countTokens());
while(st1.hasMoreTokens())
{
System.out.println(st1.nextToken());
}
}
}
String str1 = "Awake@arise*stop/notmuntil@goal*reach";
StringTokenizer st1 = new StringTokenizer(str1, "@,m,*,/");
The delimiters in the string str1 are @, m, * and / and these are supplied as second parameter in the constructor. Now, the StringTokenizer tokenizes as per these delimiters supplied.
A similar class exist that tokenizes a stream of data – StreamTokenizer – Tokenizing a Stream.
Pages: 1 2
sir,
How to work with string tokenizer on a non delimited data(continuous data without any separators)?
Thanks in advance for your help.
Then on what condition they must be tokenized. Continuous means, even no white space. Think of.