StringTokenizer class in Java, stringtokenizerjava
StringTokenizer is a string-separated parsing Type and belongs to: Java. util package.
1. StringTokenizer Constructor
StringTokenizer (String str): constructs 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): constructs a StringTokenizer object to parse str and provides a specified separator.
StringTokenizer (String str, String delim, boolean returnDelims): constructs a StringTokenizer object to parse str, provides a specified separator, and specifies whether to return a separator.
2. Some common StringTokenizer Methods
Note:
1. All methods are public;
2. Writing format: [modifier] <return type> <method name ([parameter list])>
Int countTokens (): the number of times the nextToken method is called.
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 4, return results with the specified separator.
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 ());
}