StringTokenizer class in Java, stringtokenizerjava

Source: Internet
Author: User

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 ());
}

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.