⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javautil.doc8.html

📁 java语言规范
💻 HTML
字号:
<html>
<head>
<title>The Java Language Specification The Package java.util</title>
</head>
<body BGCOLOR=#eeeeff text=#000000 LINK=#0000ff VLINK=#000077 ALINK=#ff0000>
 
<a href="index.html">Contents</a> | <a href="javautil.doc7.html">Prev</a> | <a href="javautil.doc9.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<hr><br>
 
<a name="7648"></a>
<center><h1>21.10  The Class  <code>java.util.StringTokenizer</code></h1></center>
<a name="22142"></a>
The <code>StringTokenizer</code> class provides a way to break a <code>String</code> into tokens. The 
tokenizing method used by this class is much simpler than the one used by the 
class <code>java.io.StreamTokenizer</code>. For example, a <code>StringTokenizer</code> does not 
distinguish among identifiers, numbers, and quoted strings; moreover, it does not 
recognize and skip comments.
<p><a name="22227"></a>
A <code>StringTokenizer</code> can serve as an <code>Enumeration</code> <a href="javautil.doc.html#23147">(&#167;21.1)</a>.<p>
<pre><a name="7649"></a>public class <code><b>StringTokenizer</b></code> implements Enumeration {
<a name="7650"></a>	public <code><b>StringTokenizer</b></code>(String str, String delim,
<a name="22141"></a>		boolean returnTokens);
<a name="7651"></a>	public <code><b>StringTokenizer</b></code>(String str, String delim);
<a name="7652"></a>	public <code><b>StringTokenizer</b></code>(String str);
<a name="7653"></a>	public boolean <code><b>hasMoreTokens</b></code>();
<a name="7654"></a>	public String <code><b>nextToken</b></code>();
<a name="7655"></a>	public String <code><b>nextToken</b></code>(String delim);
<a name="7656"></a>	public boolean <code><b>hasMoreElements</b></code>();
<a name="7657"></a>	public Object <code><b>nextElement</b></code>();
<a name="7658"></a>	public int <code><b>countTokens</b></code>();
<a name="7659"></a>}
</pre><a name="22157"></a>
A <code>StringTokenizer</code> simply divides characters into classes: delimiters and other characters. The tokenizer behaves in one of two ways, depending on whether it was created with <code>returnTokens</code> having the value <code>true</code> or <code>false</code>.<p>
<a name="22162"></a>
If <code>returnTokens</code> is <code>false</code>, delimiter characters merely serve to separate tokens of interest. A token is thus a maximal sequence of consecutive characters that are not delimiters.<p>
<a name="22169"></a>
If <code>returnTokens</code> is <code>true</code>, delimiter characters are themselves considered to be tokens of interest. A token is thus either one delimiter character or a maximal sequence of consecutive characters that are not delimiters.<p>
<a name="22187"></a>
A <code>StringTokenizer</code> internally maintains a current position within the <code>String</code> to be tokenized. Some operations advance this current position past the characters processed.<p>
<a name="22213"></a>
A token is returned by taking a substring <a href="javalang.doc11.html#14007">(&#167;20.12.32)</a> of the string that was used to create the <code>StringTokenizer</code>.<p>
<a name="7660"></a>
<p><font size=+1><strong>21.10.1   </strong> <code>public <code><b>StringTokenizer</b></code>(String str, String delim,<br> &#32; &#32; &#32;boolean returnTokens)</code></font>
<p>
<a name="22178"></a>
This constructor initializes a newly created <code>StringTokenizer</code> so that it will recognize
tokens within the given string <code>str</code>. All characters in the string <code>delim</code> will 
be considered delimiters. The argument <code>returnTokens</code> specifies whether delimiter
characters themselves are to be considered tokens.
<p><a name="7661"></a>
<p><font size=+1><strong>21.10.2   </strong> <code>public <code><b>StringTokenizer</b></code>(String str, String delim)</code></font>
<p>
<a name="22192"></a>
This constructor initializes a newly created <code>StringTokenizer</code> so that it will recognize
tokens within the given string <code>str</code>. All characters in the string <code>delim</code> will 
be considered delimiters. Delimiter characters themselves will not be treated as 
tokens.
<p><a name="7662"></a>
<p><font size=+1><strong>21.10.3   </strong> <code>public <code><b>StringTokenizer</b></code>(String str)</code></font>
<p>
<a name="22205"></a>
This constructor initializes a newly created <code>StringTokenizer</code> so that it will recognize
tokens within the given string <code>str</code>. All whitespace characters <a href="javalang.doc10.html#36320">(&#167;20.5.19)</a> 
will be considered delimiters. Delimiter characters themselves will not be treated 
as tokens.
<p><a name="7663"></a>
<p><font size=+1><strong>21.10.4   </strong> <code>public boolean <code><b>hasMoreTokens</b></code>()</code></font>
<p>
<a name="22211"></a>
The result is <code>true</code> if and only if there is at least one token in the string after the 
current position. If this method returns <code>true</code>, then a subsequent call to <code>nextToken</code> 
with no argument will successfully return a token.
<p><a name="7664"></a>
<p><font size=+1><strong>21.10.5   </strong> <code>public String <code><b>nextToken</b></code>()</code></font>
<p>
<a name="22212"></a>
The next token in the string after the current position is returned. The current position
is advanced beyond the recognized token.
<p><a name="7665"></a>
<p><font size=+1><strong>21.10.6   </strong> <code>public String <code><b>nextToken</b></code>(String delim)</code></font>
<p>
<a name="22233"></a>
First, the set of characters considered to be delimiters by this <code>StringTokenizer</code> 
is changed to be the characters in the string <code>delim</code>. Then the next token in the 
string after the current position is returned. The current position is advanced 
beyond the recognized token.
<p><a name="7666"></a>
<p><font size=+1><strong>21.10.7   </strong> <code>public boolean <code><b>hasMoreElements</b></code>()</code></font>
<p>
<a name="22236"></a>
This method has exactly the same behavior as <code>hasMoreTokens</code> <a href="javautil.doc8.html#7663">(&#167;21.10.4)</a>. It is 
provided so that a <code>StringTokenizer</code> can serve as an <code>Enumeration</code> <a href="javautil.doc.html#23147">(&#167;21.1)</a>.
<p><a name="7667"></a>
<p><font size=+1><strong>21.10.8   </strong> <code>public Object <code><b>nextElement</b></code>()</code></font>
<p>
<a name="22255"></a>
This method has exactly the same behavior as <code>nextToken</code> <a href="javautil.doc8.html#7664">(&#167;21.10.5)</a>. It is provided
so that a <code>StringTokenizer</code> can serve as an <code>Enumeration</code> <a href="javautil.doc.html#23147">(&#167;21.1)</a>.
<p><a name="7668"></a>
<p><font size=+1><strong>21.10.9   </strong> <code>public int <code><b>countTokens</b></code>()</code></font>
<p>
<a name="22264"></a>
The result is the number of tokens in the string after the current position, using the 
current set of delimiter characters. The current position is not advanced.
<p>

<hr>
<!-- This inserts footnotes--><p>
<a href="index.html">Contents</a> | <a href="javautil.doc7.html">Prev</a> | <a href="javautil.doc9.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<p>
<font size=-1>Java Language Specification (HTML generated by Suzette Pelouch on February 24, 1998)<br>
<i><a href="jcopyright.doc.html">Copyright &#169 1996 Sun Microsystems, Inc.</a>
All rights reserved</i>
<br>
Please send any comments or corrections to <a href="mailto:doug.kramer@sun.com">doug.kramer@sun.com</a>
</font>
</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -