StringTokenizer, stringtokenizerjava
StringTokenizer is an application class used to separate strings. It is equivalent to the split method of String.
Constructor
public StringTokenizer(String str)public StringTokenizer(String str, String delim)public StringTokenizer(String str, String delim, boolean returnDelims)
- The first parameter is the String to be separated.
- The second is delimiter character set combination.
- The third parameter indicates whether the separator is returned as a mark. If no Delimiter is specified, the default Delimiter is :"\ T \ n \ r \ f"
StringTokenizer (String str ):Construct a StringTokenizer object used to parse str. The default delimiter for java is space, tab ('\ t'), line feed (' \ n'), and carriage return ('\ R ')".
StringTokenizer (String str, String delim ):Construct a StringTokenizer object used to parse str and provide a specified separator.
StringTokenizer (String str, String delim, boolean returnDelims ):Construct a StringTokenizer object used to parse str, provide a specified separator, and specify whether to return a separator.
Method Functions
Int countTokens () // returns the number of times the nextToken method is called. If constructors 1 and 2 are used, the number of delimiters is returned. Boolean hasMoreTokens () // returns whether there are delimiters. Boolean hasMoreElements () // returns whether there are delimiters. String nextToken () // returns the String from the current position to the next separator. Object nextElement () // returns the string from the current position to the next separator. String nextToken (String delim) // similar to the above, return the result with the specified separator.
Dry Goods
String s = new String("The Java platform is the ideal platform for network computing");StringTokenizer st = new StringTokenizer(s);System.out.println( "Token Total: " + st.countTokens() );while( st.hasMoreElements() ){ System.out.println( st.nextToken() ); }
Output
Token Total: 10TheJavaplatformistheidealplatformfornetworkcomputing
String s = new String("The=Java=platform=is=the=ideal=platform=for=network=computing");StringTokenizer st = new StringTokenizer(s,"=",true);System.out.println( "Token Total: " + st.countTokens() );while( st.hasMoreElements() ){ System.out.println( st.nextToken() ); }
Output:
Token Total: 19The=Java=platform=is=the=ideal=platform=for=network=computing
I am the dividing line of tiantiao