Stringtokenizer class

Stringtokenizer is an application class used to separate string strings.

1. Constructor

Public stringtokenizer (string STR) / / construct a stringtokenizer object used to parse str. Java's default separators are "space", "tab ('\ t')", "line feed ('\ n')", "carriage return ('\ R')". Public stringtokenizer (string STR, string delim) / / construct a stringtokenizer object used to parse STR and provide a specified separator. Public stringtokenizer (string STR, string delim, Boolean returndelims) / / the first parameter is the string to be separated, the second is the collection of separated characters, and the third parameter indicates whether the separator is returned as a tag. If the separator is not specified, the default is: "\ t \ n \ R \ F"

2. Core methodology

(1) Public Boolean hasmoretokens() / / returns whether there are separators. Public string nexttoken() / / returns the string from the current position to the next delimiter

(2) Public string nextToken (string delim) / / similar to (1), returns the result with the specified delimiter

(3) Public int counttokens() / / returns the number of times the nextToken method was called. If constructors 1 and 2 are used, the number of separators is returned (example 2).

3. Examples

Code 1: 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());} the result is: token total: 10 the Java platform is the ideal platform for network computing

Excerpt from: http://blog.csdn.net/riyunzhu/article/details/7989145

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>