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

📄 javautil.doc.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="javalang.doc21.html">Prev</a> | <a href="javautil.doc1.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<hr><br>
 
<a name="32169"></a>
<p><strong>
CHAPTER 21 </strong></p>
<a name="32170"></a>
<h1>The Package java.util</h1>
<hr><p>
<a name="32171"></a>
The <code>java.util</code> package contains various utility classes and interfaces.
<p><a name="22947"></a>
Notable among these utilities is the <code>Enumeration</code> interface. An object that implements this interface will generate a series of items, delivering them on demand, one by one. Container classes such as <code>Dictionary</code> and <code>Vector</code> provide one or more methods that return an <code>Enumeration</code>.<p>
<a name="22949"></a>
A <code>BitSet</code> contains an indexed collection of bits that may be used to represent a set of nonnegative integers.<p>
<a name="22953"></a>
The class <code>Date</code> provides a convenient way to represent and manipulate time and date information. Dates may be constructed from a year, month, day of month, hour, minute, and second, and those six components, as well as the day of the week, may be extracted from a date. Time zones and daylight saving time are properly accounted for.<p>
<a name="22960"></a>
The <code>abstract</code> class <code>Dictionary</code> represents a collection of key-value pairs and allows a value to be fetched given the key. The class <code>Hashtable</code> is one concrete implementation of <code>Dictionary</code>. The class <code>Properties</code> extends <code>Hashtable</code> by allowing one table to provide default values for another and by providing standard means for reading entries from files and writing entries to files.<p>
<a name="22965"></a>
The class <code>Observable</code> provides a mechanism for notifying other objects, called "observers," whenever an <code>Observable</code> object is changed. An observer object may be any object that implements the <code>Observer</code> interface. (This notification mechanism is distinct from that provided by the <code>wait</code> and <code>notify</code> methods of class <code>Object</code> <a href="javalang.doc1.html#46442">(&#167;20.1)</a> and is not connected with the thread scheduling mechanism.)<p>
<a name="22966"></a>
The class <code>Random</code> provides an extensive set of methods for pseudorandomly generating numeric values of various primitive types and with various distributions. Each instance of class <code>Random</code> is an independent pseudorandom generator.<p>
<a name="22987"></a>
A <code>StringTokenizer</code> provides an easy way to divide strings into tokens. The set of characters that delimit tokens is programmable. The tokenizing method 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="22971"></a>
The classes <code>Vector</code> and <code>Stack</code> are simple container classes that provide extensions to the capabilities of Java arrays. A <code>Vector</code>, unlike a Java array, can change its size, and many convenient methods are provided for adding, removing, and searching for items. A <code>Stack</code> is a <code>Vector</code> with additional operations such as <code>push</code> and <code>pop</code>.<p>
<a name="22937"></a>
The hierarchy of classes defined in package <code>java.util</code> is as follows. (Classes whose names are shown here in <code><b>boldface</b></code> are in package <code>java.util</code>; the others are in package <code>java.lang</code> and are shown here to clarify subclass relationships.)<p>
<pre><a name="23291"></a>Object												<code><a href="javalang.doc1.html#46442">&#167;20.1</a>
</code><a name="22927"></a>	interface <code><b>Enumeration												<a href="javautil.doc.html#23147">&#167;21.1</a>
</b></code><a name="22870"></a>	<code><b>BitSet												<a href="javautil.doc1.html#7404">&#167;21.2</a>
</b></code><a name="22871"></a>	<code><b>Date												<a href="javautil.doc2.html#7433">&#167;21.3</a>
</b></code><a name="22872"></a>	<code><b>Dictionary												<a href="javautil.doc3.html#7498">&#167;21.4</a>
</b></code><a name="22896"></a>		<code><b>Hashtable												<a href="javautil.doc4.html#23193">&#167;21.5</a>
</b></code><a name="22899"></a>			<code><b>Properties												<a href="javautil.doc5.html#23061">&#167;21.6</a>
</b></code><a name="22877"></a>	<code><b>Observable												<a href="javautil.doc6.html#7569">&#167;21.7</a>
</b></code><a name="24801"></a>	interface <code><b>Observer												<a href="javautil.doc6.html#7590">&#167;21.8</a>
</b></code><a name="22881"></a>	<code><b>Random												<a href="javautil.doc7.html#7616">&#167;21.9</a>
</b></code><a name="22933"></a>	<code><b>StringTokenizer												<a href="javautil.doc8.html#7648">&#167;21.10</a>
</b></code><a name="22882"></a>	<code><b>Vector												<a href="javautil.doc9.html#7669">&#167;21.11</a>
</b></code><a name="22921"></a>		<code><b>Stack												<a href="javautil.doc10.html#24949">&#167;21.12</a>
</b></code><a name="23296"></a>	Throwable<code><b>												</b></code><a href="javalang.doc20.html#46198">&#167;20.22</a>
<a name="23297"></a>		Exception
<a name="23298"></a>			RuntimeException
<a name="22906"></a>				<code><b>EmptyStackException												<a href="javautil.doc11.html#26490">&#167;21.13</a>
</b></code><a name="22913"></a>				<code><b>NoSuchElementException												<a href="javautil.doc12.html#23170">&#167;21.14</a>
</b></code></pre><a name="23147"></a>
<h1>21.1  The Interface  <code>java.util.Enumeration</code></h1>
<a name="23148"></a>
An object that implements the <code>Enumeration</code> interface will generate a series of 
elements, one at a time. Successive calls to the <code>nextElement</code> method will return 
successive elements of the series.
<p><pre><a name="23149"></a>public interface <code><b>Enumeration</b></code> {
<a name="23150"></a>	public boolean <code><b>hasMoreElements</b></code>();
<a name="23151"></a>	public Object <code><b>nextElement</b></code>() throws NoSuchElementException;
<a name="23152"></a>}
</pre><a name="23153"></a>
<p><font size=+1><strong>21.1.1   </strong> <code>public boolean <code><b>hasMoreElements</b></code>()</code></font>
<p>
<a name="23154"></a>
The result is <code>true</code> if and only if this enumeration object has at least one more element
to provide.
<p><a name="23156"></a>
<p><font size=+1><strong>21.1.2   </strong> <code>public Object <code><b>nextElement</b></code>()<br>throws NoSuchElementException</code></font>
<p>
<a name="23157"></a>
If this enumeration object has at least one more element to provide, such an element
is returned; otherwise, a <code>NoSuchElementException</code> is thrown.
<p><a name="23158"></a>
As an example, the following code prints every key in the hashtable <code>ht</code> and its length. The method <code>keys</code> returns an enumeration that will deliver all the keys, and we suppose that the keys are, in this case, known to be strings:<p>
<pre><a name="23159"></a>
Enumeration e = ht.keys();
<a name="23160"></a>while (e.hasMoreElements()) {
<a name="23161"></a>	String key = (String)e.nextElement();
<a name="23162"></a>	System.out.println(key + " " + key.length());
<a name="23163"></a>}
</pre>

<hr> 
<!-- This inserts footnotes--><p>
<a href="index.html">Contents</a> | <a href="javalang.doc21.html">Prev</a> | <a href="javautil.doc1.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 + -