Go: How to use the StringTokenizer class in Java

Source: Internet
Author: User

StringTokenizer is a string-delimited parsing type, belonging to: Java.util package.

1.StringTokenizer Constructor StringTokenizer (String str): Constructs a StringTokenizer object to parse str. The default Java delimiter is "space", "tab (' \ t ')", "line feed (' \ n ')", "carriage return (' \ R ')". StringTokenizer (String str,string Delim): Constructs a StringTokenizer object to parse STR and provides a specified delimiter. StringTokenizer (String str,string delim,boolean returndelims): Constructs a StringTokenizer object to parse str, and provides a specified delimiter, at the same time, Specifies whether to return delimiters. Some common methods of 2.StringTokenizer Description: 1. All methods are public; 2. Writing format: [modifier] < return type >< method name ([parameter list]) > int Counttokens (): Returns the number of times the Nexttoken method was called. Boolean hasmoretokens (): Returns whether there is a delimiter. Boolean hasmoreelements (): Returns whether there is a delimiter. String NextToken (): Returns the string from the current position to the next delimiter. Object nextelement (): Returns the string from the current position to the next delimiter. String NextToken (String Delim): Similar to 4, returns the result with the specified delimiter.

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

Related Article

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.