What is the use of StringTokenizer

The substring method in Java can decompose a string and return a substring of the original string. If you want to split a string into words or tokens, StringTokenizer can help.

Divided by '.' And 'b'
Output:
Token: www
Token: baidu
Token: com

StringTokenizer has two commonly used methods:

1. hasMoreTokens (). This method has the same usage as the hasMoreElements () method, except that the method implemented by StringTokenizer to implement the enumeration interface can be seen from the StringTokenizer declaration: class StringTokenizer implements enumeration .

2. nextToken (). This method is used in the same way as the nextElement () method and returns the next token of this StringTokenizer.

The three constructors of StringTokenizer:

1.StringTokenizer (String str). By default, "\ t \ n \ r \ f" (preceded by a space, not in quotation marks) is the separator.
Source:

/**
* Constructs a string tokenizer for the specified string. The
* tokenizer uses the default delimiter set, which is
* "& nbsp; & # 92; t & # 92; n & # 92; r & # 92; f" : the space character,
* the tab character, the newline character, the carriage-return character,
* and the form-feed character. Delimiter characters themselves will
* not be treated as tokens.
*
* @param str a string to be parsed.
* @exception NullPointerException if str is null
*/
public StringTokenizer (String str) {
this (str, "\ t \ n \ r \ f", false);
}

Output:
Token: www
Token: baidu
Token: com

Output:
Token: www
Token :.
Token: baidu
Token :.
Token: com