The stringtokenizer class is actually rarely used in real projects, right? But this class is really practical, because it can split a string according to its own method according to certain rules.
String S = new string ("the Java platform is the ideal platform for network computing ");
// The default constructor. The default space is the separator.
Stringtokenizer ST = new stringtokenizer (s );
// You can split strings according to your own rules. The current rule is to use "L" as the separator.
Stringtokenizer ST1 = new stringtokenizer (S, "L ");
// Here, true means "L" is also used as a token. If the parameter is set to false, "l" is not used as a token.
Stringtokenizer st2 = new stringtokenizer (S, "L", true );
System. Out. println ("token Total:" + st. counttokens ());
While (St. hasmoreelements ()){
System. Out. println (St. nextelement ());
}
However, the stringtoken class is not recommended in the JDK document. It is saved in JDK as a legacy class. We advocate
The split method of the string class or the java. util. RegEx package.
The following code writes the split method of string:
Public Class AA {
Public static void main (string ARGs [])
{
String S = "I just like it. No and is love ";
// Here we must use // to specify that we use "." To separate strings. If you want to separate a string with different characters, you can use "|" as the connector.
String [] Ss = S. Split ("//. | and ");
Int I = 0;
While (I <ss. length)
{
System. Out. println (ss [I]);
I ++;
}
}
}
The running result is as follows:
I just like it
No
Yes