StringTokenizer is a string-delimited resolution type, belonging to: Java.util package.
1.StringTokenizer Constructors
StringTokenizer (String str): Constructs a StringTokenizer object to parse str. The Java default separator is space, tab (' \ t '), line break (' \ n '), ' carriage return (' \ R ').
StringTokenizer (String str,string Delim): Constructs a StringTokenizer object to parse STR and provides a specified delimiter.
StringTokenizer (String str,string delim,boolean returndelims): Constructs a StringTokenizer object to parse STR and provides a specified delimiter, while Specifies whether to return the separator character.
Some common methods of 2.StringTokenizer
Description
1. All methods are public;
2. Writing format: [modifier] < return type >< method name ([parameter list]) >
int Counttokens (): Returns the number of times the Nexttoken method was invoked.
Boolean hasmoretokens (): Returns whether delimiters are also available.
Boolean hasmoreelements (): Returns whether delimiters are also available.
String Nexttoken (): Returns a string from the current position to the next separator.
Object nextelement (): Returns a string from the current position to the next separator.
String Nexttoken (String Delim): Similar to 4, returns the result with the specified delimiter.
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 ());
}
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 ());
}