Extension:Pattern.split replaces String.Split http://www.cnblogs.com/gnivor/p/4386978.html
StringTokenizer is an application class used to separate strings.
1. Constructor function.
1. StringTokenizer (String str): Constructs a StringTokenizer object to parse str. The default Java delimiter is "space", "tab (' \ t ')", "line feed (' \ n ')", "carriage return (' \ R ')". 2. StringTokenizer (String str, string Delim): Constructs a StringTokenizer object to parse STR and provides a specified delimiter. boolean returndelims): Constructs a StringTokenizer object to parse STR and provides a specified delimiter, specifying whether to return delimiters.
2. Introduction to Methods
int Counttokens (): Returns the number of times the Nexttoken method was called. If constructors 1 and 2 are used, the number of separators is returned
Boolean hasmoreelements (): Returns whether there is a delimiter.
Boolean Hasmoretokens (): Ibid.
String NextToken (): returns the string from the current position to the next delimiter.
Object Nextelement (): same as the result, unless life returns an object instead of a string
String NextToken (String delim): Same as NextToken (), returns the result with the specified delimiter
Cases:
New String ("This was a test string"new"Token total:" + St.counttokens ()); while (St.hasmoreelements ()) { System.out.println (st.nexttoken ());}
Example 2:
String str = "100|66,55:200|567,90:102|43,54"new stringtokenizer (str, ":, |"); // default does not print separators // stringtokenizer strtoke=new stringtokenizer (str, ":, |", true); // Print Separator // stringtokenizer strtoke=new stringtokenizer (str, ":, |", false); // do not print separators while (Strtoke.hasmoretokens ()) { System.out.println (Strtoke.nexttoken ());}
Note that the StringTokenizer delimiter does not need to use escape characters
3. The difference from split
String.Split () uses regular expressions, while StringTokenizer only uses characters that are split verbatim.
If you do not use a regular expression (StringTokenizer also does not work with regular expressions), StringTokenizer is the most efficient in intercepting strings. 】
The use of Java Learning Note--stringtokenizer