The java.util.StringTokenizer class allows an application to break a string into tokens.

 

StringTokenizer(String str)

This constructor a string tokenizer for the specified string.

 

StringTokenizer(String str, String delim)

This constructor constructs string tokenizer for the specified string.

 

The 6 useful methods of StringTokenizer class are as follows:

Public method Description
boolean hasMoreTokens() checks if there is more tokens available.
String nextToken() returns the next token from the StringTokenizer object.
String nextToken(String delim) returns the next token based on the delimeter.
boolean hasMoreElements() same as hasMoreTokens() method.
Object nextElement() same as nextToken() but its return type is Object.
int countTokens() returns the total number of tokens.

 

Normal Example

 

Java StringTokenizer With Multiple De-limiters

for this we have to specify the Delimiters , separated by //. for Example

StringTokenizer tokenizer = new StringTokenizer(s, "// //!//,//?//.//_//'//@)");