📄 java.util.hashtable.html
字号:
<!-- Automatically generated with polardoc Version 1.0.7 on Mon Dec 14 23:58:45 MST 1998 -->
<!-- java.util.Hashtable | Do not remove or edit this line! -->
<STYLE TYPE="text/css"> <!-- A.nound {text-decoration:none; color:black} --> </STYLE>
<HTML>
<HEAD>
<TITLE>
Class java.util.Hashtable
</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#0000FF" ALINK="#0000FF">
<A NAME="_top_"></A>
<PRE>
<A HREF="Packages.html">All Packages</A> <A HREF="Package-java.util.html">This Package</A> <A HREF="Tree.html">Class Hierarchy</A> <A HREF="Search.html">Class Search</A> <A HREF="AllNames.html">Index</A>
</PRE>
<HR SIZE=1 ALIGN=left WIDTH="98%">
<B><FONT FACE="Arial,Helvetica" SIZE=+2>
Class java.util.Hashtable
</FONT></B>
<PRE>
<A HREF="java.lang.Object.html">java.lang.Object</A>
|
+----<A HREF="java.util.Dictionary.html">java.util.Dictionary</A>
|
+----java.util.Hashtable
</PRE>
<P><TABLE BGCOLOR="#00ccff" WIDTH=100% CELLSPACING=0 CELLPADDING=1 BORDER=0> <TR> <TD><FONT FACE="arial,helvetica" SIZE=+1><B> Summary</B></FONT></TD> </TR> </TABLE>
<A NAME="_Summary_"></A>
<PRE>
public class <STRONG>Hashtable</STRONG>
extends java.util.<A HREF="java.util.Dictionary.html">Dictionary</A>
implements java.util.<A HREF="java.util.Map.html">Map</A>,
java.lang.<A HREF="java.lang.Cloneable.html">Cloneable</A>,
java.io.<A HREF="java.io.Serializable.html">Serializable</A>
{
// Constructors 4
public <A HREF="#Hashtable()">Hashtable</A>();
public <A HREF="#Hashtable(int)">Hashtable</A>(int);
public <A HREF="#Hashtable(int, float)">Hashtable</A>(int, float);
public <A HREF="#Hashtable(java.util.Map)">Hashtable</A>(<A CLASS=nound HREF="java.util.Map.html">Map</A>);
// Methods 20
public synchronized void <A HREF="#clear()">clear</A>();
public synchronized <A CLASS=nound HREF="java.lang.Object.html">Object</A> <A HREF="#clone()">clone</A>();
public synchronized boolean <A HREF="#contains(java.lang.Object)">contains</A>(<A CLASS=nound HREF="java.lang.Object.html">Object</A>);
public synchronized boolean <A HREF="#containsKey(java.lang.Object)">containsKey</A>(<A CLASS=nound HREF="java.lang.Object.html">Object</A>);
public boolean <A HREF="#containsValue(java.lang.Object)">containsValue</A>(<A CLASS=nound HREF="java.lang.Object.html">Object</A>);
public synchronized <A CLASS=nound HREF="java.util.Enumeration.html">Enumeration</A> <A HREF="#elements()">elements</A>();
public <A CLASS=nound HREF="java.util.Set.html">Set</A> <A HREF="#entrySet()">entrySet</A>();
public synchronized boolean <A HREF="#equals(java.lang.Object)">equals</A>(<A CLASS=nound HREF="java.lang.Object.html">Object</A>);
public synchronized <A CLASS=nound HREF="java.lang.Object.html">Object</A> <A HREF="#get(java.lang.Object)">get</A>(<A CLASS=nound HREF="java.lang.Object.html">Object</A>);
public synchronized int <A HREF="#hashCode()">hashCode</A>();
public boolean <A HREF="#isEmpty()">isEmpty</A>();
public <A CLASS=nound HREF="java.util.Set.html">Set</A> <A HREF="#keySet()">keySet</A>();
public synchronized <A CLASS=nound HREF="java.util.Enumeration.html">Enumeration</A> <A HREF="#keys()">keys</A>();
public synchronized <A CLASS=nound HREF="java.lang.Object.html">Object</A> <A HREF="#put(java.lang.Object, java.lang.Object)">put</A>(<A CLASS=nound HREF="java.lang.Object.html">Object</A>, <A CLASS=nound HREF="java.lang.Object.html">Object</A>);
public synchronized void <A HREF="#putAll(java.util.Map)">putAll</A>(<A CLASS=nound HREF="java.util.Map.html">Map</A>);
protected void <A HREF="#rehash()">rehash</A>();
public synchronized <A CLASS=nound HREF="java.lang.Object.html">Object</A> <A HREF="#remove(java.lang.Object)">remove</A>(<A CLASS=nound HREF="java.lang.Object.html">Object</A>);
public int <A HREF="#size()">size</A>();
public synchronized <A CLASS=nound HREF="java.lang.String.html">String</A> <A HREF="#toString()">toString</A>();
public <A CLASS=nound HREF="java.util.Collection.html">Collection</A> <A HREF="#values()">values</A>();
}
</PRE>
<P>
<DL>
<P>
This class implements a hashtable, which maps keys to values. Any non-<code>null</code> object can be used as a key or as a value. <p> To successfully store and retrieve objects from a hashtable, the objects used as keys must implement the <code>hashCode</code> method and the <code>equals</code> method. <p> An instance of <code>Hashtable</code> has two parameters that affect its performance: <i>initial capacity</i> and <i>load factor</i>. The <i>capacity</i> is the number of <i>buckets</i> in the hash table, and the <i>initial capacity</i> is simply the capacity at the time the hash table is created. Note that the hash table is <i>open</i>: in the case a "hash collision", a single bucket stores multiple entries, which must be searched sequentially. The <i>load factor</i> is a measure of how full the hash table is allowed to get before its capacity is automatically increased. When the number of entries in the hashtable exceeds the product of the load factor and the current capacity, the capacity is increased by calling the <code>rehash</code> method.<p> Generally, the default load factor (.75) offers a good tradeoff between time and space costs. Higher values decrease the space overhead but increase the time cost to look up an entry (which is reflected in most <tt>Hashtable</tt> operations, including <tt>get</tt> and <tt>put</tt>).<p> The initial capacity controls a tradeoff between wasted space and the need for <code>rehash</code> operations, which are time-consuming. No <code>rehash</code> operations will <i>ever</i> occur if the initial capacity is greater than the maximum number of entries the <tt>Hashtable</tt> will contain divided by its load factor. However, setting the initial capacity too high can waste space.<p> If many entries are to be made into a <code>Hashtable</code>, creating it with a sufficiently large capacity may allow the entries to be inserted more efficiently than letting it perform automatic rehashing as needed to grow the table. <p> This example creates a hashtable of numbers. It uses the names of the numbers as keys: <p><blockquote><pre> Hashtable numbers = new Hashtable(); numbers.put("one", new Integer(1)); numbers.put("two", new Integer(2)); numbers.put("three", new Integer(3)); </pre></blockquote> <p> To retrieve a number, use the following code: <p><blockquote><pre> Integer n = (Integer)numbers.get("two"); if (n != null) { System.out.println("two = " + n); } </pre></blockquote> <p> As of JDK1.2, this class has been retrofitted to implement Map, so that it becomes a part of Java's collection framework. Unlike the new collection implementations, Hashtable is synchronized.<p> The Iterators returned by the iterator and listIterator methods of the Collections returned by all of Hashtable's "collection view methods" are <em>fail-fast</em>: if the Hashtable is structurally modified at any time after the Iterator is created, in any way except through the Iterator's own remove or add methods, the Iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the Iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future. The Enumerations returned by Hashtable's keys and values methods are <em>not</em> fail-fast.
<P>
</DL>
<P> <B>See Also:</B>
<A HREF="java.lang.Object.html#equals(java.lang.Object)">equals</A>, <A HREF="java.lang.Object.html#hashCode()">hashCode</A>, <A HREF="java.util.Hashtable.html#rehash()">rehash</A>, <A HREF="java.util.Collection.html">Collection</A>, <A HREF="java.util.Map.html">Map</A>, <A HREF="java.util.HashMap.html">HashMap</A>, <A HREF="java.util.TreeMap.html">TreeMap</A><P>
<BR><TABLE BGCOLOR="#00ccff" WIDTH=100% CELLSPACING=0 CELLPADDING=1 BORDER=0> <TR> <TD><FONT FACE="arial,helvetica" SIZE=+1><B> Cross Reference</B></FONT></TD> </TR> </TABLE>
<BR><DL>
<DT><B>Extended By: </B>
<DD><A HREF="java.util.Properties.html">Properties</A><P>
</DL><BR>
<BR><BR>
<BR><TABLE BGCOLOR="#00ccff" WIDTH=100% CELLSPACING=0 CELLPADDING=1 BORDER=0> <TR> <TD><FONT FACE="arial,helvetica" SIZE=+1><B> Constructors</B></FONT></TD> </TR> </TABLE>
<TABLE WIDTH=100% CELLSPACING=0 CELLPADDING=1 BORDER=0> <TR> <TD WIDTH=80%>
<BR><H3><A NAME="Hashtable"><FONT COLOR="#FFCC00">·</FONT></A>
<A NAME="Hashtable(int, float)">Hashtable</A> </H3>
</TD> <TD ALIGN=right WIDTH=20%> <FONT SIZE="-2"><A HREF="#_Summary_">Summary</A> | <A HREF=#_top_>Top</A></FONT> </TD> </TR> </TABLE>
<PRE>
public Hashtable(int initialCapacity,
float loadFactor) </PRE>
<BLOCKQUOTE>
<DL>
<P>
Constructs a new, empty hashtable with the specified initial capacity and the specified load factor.
<P>
<TABLE WIDTH="87%" BORDER=1 CELLPADDING=3 CELLSPACING=0> <TR VALIGN=TOP BGCOLOR="#CCCCCC"> <TD><B>Parameter</B></TD> <TD><B>Description</B></TD> </TR>
<TR VALIGN=TOP> <TD><I> initialCapacity</I></TD> <TD>the initial capacity of the hashtable.</TD></TR>
<TR VALIGN=TOP> <TD><I> loadFactor</I></TD> <TD>the load factor of the hashtable.</TD></TR>
</TABLE><P>
<DT> <B>Throws:</B> <A HREF="java.lang.IllegalArgumentException.html">IllegalArgumentException</A>
<DD> if the initial capacity is less than zero, or if the load factor is nonpositive.
</DL>
</BLOCKQUOTE> <BR>
<TABLE WIDTH=100% CELLSPACING=0 CELLPADDING=1 BORDER=0> <TR> <TD WIDTH=80%>
<BR><H3><A NAME="Hashtable"><FONT COLOR="#FFCC00">·</FONT></A>
<A NAME="Hashtable(int)">Hashtable</A> </H3>
</TD> <TD ALIGN=right WIDTH=20%> <FONT SIZE="-2"><A HREF="#_Summary_">Summary</A> | <A HREF=#_top_>Top</A></FONT> </TD> </TR> </TABLE>
<PRE>
public Hashtable(int initialCapacity) </PRE>
<BLOCKQUOTE>
<DL>
<P>
Constructs a new, empty hashtable with the specified initial capacity and default load factor, which is <tt>0.75</tt>.
<P>
<TABLE WIDTH="87%" BORDER=1 CELLPADDING=3 CELLSPACING=0> <TR VALIGN=TOP BGCOLOR="#CCCCCC"> <TD><B>Parameter</B></TD> <TD><B>Description</B></TD> </TR>
<TR VALIGN=TOP> <TD><I> initialCapacity</I></TD> <TD>the initial capacity of the hashtable.</TD></TR>
</TABLE><P>
<DT> <B>Throws:</B> <A HREF="java.lang.IllegalArgumentException.html">IllegalArgumentException</A>
<DD> if the initial capacity is less than zero.
</DL>
</BLOCKQUOTE> <BR>
<TABLE WIDTH=100% CELLSPACING=0 CELLPADDING=1 BORDER=0> <TR> <TD WIDTH=80%>
<BR><H3><A NAME="Hashtable"><FONT COLOR="#FFCC00">·</FONT></A>
<A NAME="Hashtable()">Hashtable</A> </H3>
</TD> <TD ALIGN=right WIDTH=20%> <FONT SIZE="-2"><A HREF="#_Summary_">Summary</A> | <A HREF=#_top_>Top</A></FONT> </TD> </TR> </TABLE>
<PRE>
public Hashtable() </PRE>
<BLOCKQUOTE>
<DL>
<P>
Constructs a new, empty hashtable with a default capacity and load factor, which is <tt>0.75</tt>.
<P>
</DL>
</BLOCKQUOTE> <BR>
<TABLE WIDTH=100% CELLSPACING=0 CELLPADDING=1 BORDER=0> <TR> <TD WIDTH=80%>
<BR><H3><A NAME="Hashtable"><FONT COLOR="#FFCC00">·</FONT></A>
<A NAME="Hashtable(java.util.Map)">Hashtable</A> </H3>
</TD> <TD ALIGN=right WIDTH=20%> <FONT SIZE="-2"><A HREF="#_Summary_">Summary</A> | <A HREF=#_top_>Top</A></FONT> </TD> </TR> </TABLE>
<PRE>
public Hashtable(<A HREF="java.util.Map.html">Map</A> t) </PRE>
<BLOCKQUOTE>
<DL>
<P>
Constructs a new hashtable with the same mappings as the given Map. The hashtable is created with a capacity of twice the number of entries in the given Map or 11 (whichever is greater), and a default load factor, which is <tt>0.75</tt>.
<P>
</DL>
</BLOCKQUOTE> <BR>
<BR><TABLE BGCOLOR="#00ccff" WIDTH=100% CELLSPACING=0 CELLPADDING=1 BORDER=0> <TR> <TD><FONT FACE="arial,helvetica" SIZE=+1><B> Methods</B></FONT></TD> </TR> </TABLE>
<TABLE WIDTH=100% CELLSPACING=0 CELLPADDING=1 BORDER=0> <TR> <TD WIDTH=80%>
<BR><H3><A NAME="size"><FONT COLOR="#FF0000">·</FONT></A>
<A NAME="size()">size</A> </H3>
</TD> <TD ALIGN=right WIDTH=20%> <FONT SIZE="-2"><A HREF="#_Summary_">Summary</A> | <A HREF=#_top_>Top</A></FONT> </TD> </TR> </TABLE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -