From previous studies, we know that all classes are subclasses or indirect subclasses of the Object class in the java.lang package by default. There is a public String toString() method in the Object class. An object can obtain the string representation of the object by calling this method.
The general format of the string returned by an object calling the toString() method is:
The name of the class that created the object@The string representation of the reference to the object
Of course, subclasses or indirect subclasses of the Object class can also override the toString() method. The Date class in the java.util package overrides the toString method, and the overridden method returns a string representation of the time.
When analyzing a string and decomposing the string into words that can be used independently, you can use the StringTokenizer class in the java.util package. This class has two commonly used constructors:
1) StringTokenizer(String s) constructs an analyzer for string s, using Java's default delimiters, namely space (), tab (t), newline (n), and carriage return (r) .
2) StringTokenizer(String s, String delim) constructs an analyzer for string s, and the characters in delim are used as delimiters.
Each StringTokenizer object is called a string analyzer . An analyzer can use the nextToken() method to obtain the language symbols in the string one by one. Whenever a language symbol is obtained, the value of the count variable in the string analyzer is automatically - 1. The initial value of this count variable is equal to the number of words in the string.
The hasMoreTokens() method in the StringTokenizer class returns true as long as there are language symbols in the string, that is, as long as the value of the count variable is greater than 0, otherwise it returns false. Moreover, the analyzer can also call the countTokens() method to obtain the value of the count variable in the analyzer.