StringTokenizer is a string-delimited parsing type, belonging to: Java.util package.
1.StringTokenizer Constructor StringTokenizer (String str): Constructs a StringTokenizer object to parse str. The default Java delimiter is "space", "tab (' \ t ')", "line feed (' \ 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, at the same time, Specifies whether to return delimiters. 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 called. Boolean hasmoretokens (): Returns whether there is a delimiter. Boolean hasmoreelements (): Returns whether there is a delimiter. String NextToken (): Returns the string from the current position to the next delimiter. Object nextelement (): Returns the string from the current position to the next delimiter. 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 ());