Java practice (netbeans Development) -- stringtokenizer implements array Segmentation

Source: Internet
Author: User

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:

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.