StringTokenizer, stringtokenizerjava

Source: Internet
Author: User

StringTokenizer, stringtokenizerjava

StringTokenizer is an application class used to separate strings. It is equivalent to the split method of String.

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 delimiter character set combination.
  • The third parameter indicates whether the separator is returned as a mark. If no Delimiter is specified, the default Delimiter is :"\ T \ n \ r \ f"

StringTokenizer (String str ):Construct 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 ):Construct a StringTokenizer object used to parse str and provide a specified separator.

StringTokenizer (String str, String delim, boolean returnDelims ):Construct a StringTokenizer object used to parse str, provide a specified separator, and specify whether to return a separator.

Method Functions
Int countTokens () // returns the number of times the nextToken method is called. If constructors 1 and 2 are used, the number of delimiters is returned. 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 the above, return the result with the specified separator.
Dry Goods
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() );    }

Output

Token Total: 10TheJavaplatformistheidealplatformfornetworkcomputing
 
 
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() );    }

Output:

Token Total: 19The=Java=platform=is=the=ideal=platform=for=network=computing
I am the dividing line of tiantiao

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.