📄 javautil.doc3.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.doc2.html">Prev</a> | <a href="javautil.doc4.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<hr><br>
<a name="7498"></a>
<center><h1>21.4 The Class <code>java.util.Dictionary</code></h1></center>
<a name="21219"></a>
A <code>Dictionary</code> is an object that associates <i>elements</i> with <i>keys</i>. Every key and
every element is an object. In any one <code>Dictionary</code>, every key is associated at
most one element. Given a <code>Dictionary</code> and a key, the associated element can be
looked up.
<p><pre><a name="7499"></a>public abstract class <code><b>Dictionary</b></code> {
<a name="7500"></a> abstract public int <code><b>size</b></code>();
<a name="7501"></a> abstract public boolean <code><b>isEmpty</b></code>();
<a name="7504"></a> abstract public Object <code><b>get</b></code>(Object key)
<a name="21275"></a> throws NullPointerException;
<a name="21277"></a> abstract public Object <code><b>put</b></code>(Object key, Object element)
<a name="7505"></a> throws NullPointerException;
<a name="21282"></a> abstract public Object <code><b>remove</b></code>(Object key)
<a name="7506"></a> throws NullPointerException;
<a name="21244"></a> abstract public Enumeration <code><b>keys</b></code>();
<a name="21245"></a> abstract public Enumeration <code><b>elements</b></code>();
<a name="7507"></a>}
</pre><a name="21494"></a>
As a rule, the <code>equals</code> method <a href="javalang.doc1.html#14865">(§20.1.3)</a> should be used by implementations of the class <code>Dictionary</code> to decide whether two keys are the same.<p>
<a name="7508"></a>
<p><font size=+1><strong>21.4.1 </strong> <code>abstract public int <code><b>size</b></code>()</code></font>
<p>
<a name="21220"></a>
The general contract for the <code>size</code> method is that it returns the number of entries
(distinct keys) in this dictionary.
<p><a name="7509"></a>
<p><font size=+1><strong>21.4.2 </strong> <code>abstract public boolean <code><b>isEmpty</b></code>()</code></font>
<p>
<a name="21224"></a>
The general contract for the <code>isEmpty</code> method is that the result is <code>true</code> if and only
if this dictionary contains no entries.
<p><a name="7512"></a>
<p><font size=+1><strong>21.4.3 </strong> <code>abstract public Object <code><b>get</b></code>(Object key)<br>throws NullPointerException</code></font>
<p>
<a name="21248"></a>
The general contract for the <code>isEmpty</code> method is that if this dictionary contains an
entry for the specified <code>key</code>, the associated element is returned; otherwise, <code>null</code> is
returned.
<p><a name="21249"></a>
If the <code>key</code> is <code>null</code>, a <code>NullPointerException</code> is thrown.<p>
<a name="7513"></a>
<p><font size=+1><strong>21.4.4 </strong> <code>abstract public Object <code><b>put</b></code>(Object key, Object element)<br>throws NullPointerException</code></font>
<p>
<a name="21259"></a>
The general contract for the <code>put</code> method is that it adds an entry to this dictionary.
<p><a name="21295"></a>
If this dictionary already contains an entry for the specified <code>key</code>, the element already in this dictionary for that <code>key</code> is returned, after modifying the entry to contain the new <code>element</code>.<p>
<a name="21304"></a>
If this dictionary does not already have an entry for the specified <code>key</code>, an entry is created for the specified <code>key</code> and <code>element</code>, and <code>null</code> is returned.<p>
<a name="21260"></a>
If the <code>key</code> or the <code>element</code> is <code>null</code>, a <code>NullPointerException</code> is thrown.<p>
<a name="7514"></a>
<p><font size=+1><strong>21.4.5 </strong> <code>abstract public Object <code><b>remove</b></code>(Object key)<br>throws NullPointerException</code></font>
<p>
<a name="21477"></a>
The general contract for the <code>remove</code> method is that it removes an entry from this
dictionary.
<p><a name="21318"></a>
If this dictionary contains an entry for the specified <code>key</code>, the element in this dictionary for that <code>key</code> is returned, after removing the entry from this dictionary.<p>
<a name="21319"></a>
If this dictionary does not already have an entry for the specified <code>key</code>, <code>null</code> is returned.<p>
<a name="21320"></a>
If the <code>key</code> is <code>null</code>, a <code>NullPointerException</code> is thrown.<p>
<a name="21235"></a>
<p><font size=+1><strong>21.4.6 </strong> <code>abstract public Enumeration <code><b>keys</b></code>()</code></font>
<p>
<a name="21342"></a>
The general contract for the <code>keys</code> method is that an <code>Enumeration</code> <a href="javautil.doc.html#23147">(§21.1)</a> is
returned that will generate all the keys for which this dictionary contains entries.
<p><a name="21236"></a>
<p><font size=+1><strong>21.4.7 </strong> <code>abstract public Enumeration <code><b>elements</b></code>()</code></font>
<p>
<a name="21351"></a>
The general contract for the <code>elements</code> method is that an <code>Enumeration</code> <a href="javautil.doc.html#23147">(§21.1)</a> is
returned that will generate all the elements contained in entries in this dictionary.
<p>
<hr>
<!-- This inserts footnotes--><p>
<a href="index.html">Contents</a> | <a href="javautil.doc2.html">Prev</a> | <a href="javautil.doc4.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 © 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 + -