Reference:
Stringtokenizer exists in the Java. util. stringtokenizer package and is an application class used to separate strings. It is equivalent to the split function of VB.
1. 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 the delimiter character set combination, and the third parameter indicates whether the separator is returned as a mark. If no Delimiter is specified, the default value is: "/T/N/R/F"
2. Core Methods
Public Boolean hasmoretokens ()
Public String nexttoken ()
Public String nexttoken (string delim)
Public int counttokens ()
In fact, there are three methods. You can also specify the delimiter when the Delimiter is returned, and the last separator is used in the future.
3. Redundant Methods
Public Boolean hasmoreelements ()
Public Boolean hasmoreelements ()
This class implements the enumeration interface, so there is no need to implement these two methods.
Its name is stringtokenizer, and returning an object is meaningless.
Next, let's take a look at how to split data:
Input: Kunming, fujiian, Lanzhou, Shangdong
Output: Kunming
Fuji
Lanzhou
Shangdong
First, create a Java class: stringtokenizer1.java
Next, write the code:
Running result: