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

📄 weakhashmap.html

📁 API資料大全
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc on Thu Apr 27 23:37:04 PDT 2000 --><TITLE>Java 2 Platform SE v1.3: Class  WeakHashMap</TITLE><LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style"></HEAD><BODY BGCOLOR="white"><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_top"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">  <TR ALIGN="center" VALIGN="top">  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="class-use/WeakHashMap.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>  </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><b>Java<sup><font size=-2>TM</font></sup>&nbsp;2&nbsp;Platform<br>Std.&nbsp;Ed. v1.3</b></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">&nbsp;<A HREF="../../java/util/Vector.html"><B>PREV CLASS</B></A>&nbsp;&nbsp;NEXT CLASS</FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">  <A HREF="../../index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;&nbsp;<A HREF="WeakHashMap.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">  SUMMARY: &nbsp;INNER&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: &nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><!-- =========== END OF NAVBAR =========== --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">java.util</FONT><BR>Class  WeakHashMap</H2><PRE><A HREF="../../java/lang/Object.html">java.lang.Object</A>  |  +--<A HREF="../../java/util/AbstractMap.html">java.util.AbstractMap</A>        |        +--<B>java.util.WeakHashMap</B></PRE><DL><DT><B>All Implemented Interfaces:</B> <DD><A HREF="../../java/util/Map.html">Map</A></DD></DL><HR><DL><DT>public class <B>WeakHashMap</B><DT>extends <A HREF="../../java/util/AbstractMap.html">AbstractMap</A><DT>implements <A HREF="../../java/util/Map.html">Map</A></DL><P>A hashtable-based <code>Map</code> implementation with <em>weak keys</em>. An entry in a <code>WeakHashMap</code> will automatically be removed when its key is no longer in ordinary use.  More precisely, the presence of a mapping for a given key will not prevent the key from being discarded by the garbage collector, that is, made finalizable, finalized, and then reclaimed. When a key has been discarded its entry is effectively removed from the map, so this class behaves somewhat differently than other <code>Map</code> implementations. <p> Both null values and the null key are supported.  This class has performance characteristics similar to those of the <code>HashMap</code> class, and has the same efficiency parameters of <em>initial capacity</em> and <em>load factor</em>. <p> Like most collection classes, this class is not synchronized.  A synchronized <code>WeakHashMap</code> may be constructed using the <code>Collections.synchronizedMap</code> method. <p> This class is intended primarily for use with key objects whose <code>equals</code> methods test for object identity using the <code>==</code> operator.  Once such a key is discarded it can never be recreated, so it is impossible to do a lookup of that key in a <code>WeakHashMap</code> at some later time and be surprised that its entry has been removed.  This class will work perfectly well with key objects whose <code>equals</code> methods are not based upon object identity, such as <code>String</code> instances.  With such recreatable key objects, however, the automatic removal of <code>WeakHashMap</code> entries whose keys have been discarded may prove to be confusing. <p> The behavior of the <code>WeakHashMap</code> class depends in part upon the actions of the garbage collector, so several familiar (though not required) <code>Map</code> invariants do not hold for this class.  Because the garbage collector may discard keys at any time, a <code>WeakHashMap</code> may behave as though an unknown thread is silently removing entries.  In particular, even if you synchronize on a <code>WeakHashMap</code> instance and invoke none of its mutator methods, it is possible for the <code>size</code> method to return smaller values over time, for the <code>isEmpty</code> method to return <code>false</code> and then <code>true</code>, for the <code>containsKey</code> method to return <code>true</code> and later <code>false</code> for a given key, for the <code>get</code> method to return a value for a given key but later return <code>null</code>, for the <code>put</code> method to return <code>null</code> and the <code>remove</code> method to return <code>false</code> for a key that previously appeared to be in the map, and for successive examinations of the key set, the value set, and the entry set to yield successively smaller numbers of elements. <p> Each key object in a <code>WeakHashMap</code> is stored indirectly as the referent of a weak reference.  Therefore a key will automatically be removed only after the weak references to it, both inside and outside of the map, have been cleared by the garbage collector. <p> <strong>Implementation note:</strong> The value objects in a <code>WeakHashMap</code> are held by ordinary strong references.  Thus care should be taken to ensure that value objects do not strongly refer to their own keys, either directly or indirectly, since that will prevent the keys from being discarded.  Note that a value object may refer indirectly to its key via the <code>WeakHashMap</code> itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object.  This problem may be fixed in a future release.<P><DL><DT><B>Since: </B><DD>1.2</DD><DT><B>See Also: </B><DD><A HREF="../../java/util/HashMap.html"><CODE>HashMap</CODE></A>, <A HREF="../../java/lang/ref/WeakReference.html"><CODE>WeakReference</CODE></A></DL><HR><P><!-- ======== INNER CLASS SUMMARY ======== --><A NAME="inner_classes_inherited_from_class_java.util.Map"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TD><B>Inner classes inherited from class java.util.<A HREF="../../java/util/Map.html">Map</A></B></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><A HREF="../../java/util/Map.Entry.html">Map.Entry</A></CODE></TD></TR></TABLE>&nbsp;<!-- =========== FIELD SUMMARY =========== --><!-- ======== CONSTRUCTOR SUMMARY ======== --><A NAME="constructor_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Constructor Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../java/util/WeakHashMap.html#WeakHashMap()">WeakHashMap</A></B>()</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constructs a new, empty <code>WeakHashMap</code> with the default initial capacity and the default load factor, which is <code>0.75</code>.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../java/util/WeakHashMap.html#WeakHashMap(int)">WeakHashMap</A></B>(int&nbsp;initialCapacity)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constructs a new, empty <code>WeakHashMap</code> with the given initial capacity and the default load factor, which is <code>0.75</code>.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../java/util/WeakHashMap.html#WeakHashMap(int, float)">WeakHashMap</A></B>(int&nbsp;initialCapacity,            float&nbsp;loadFactor)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constructs a new, empty <code>WeakHashMap</code> with the given initial capacity and the given load factor.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../java/util/WeakHashMap.html#WeakHashMap(java.util.Map)">WeakHashMap</A></B>(<A HREF="../../java/util/Map.html">Map</A>&nbsp;t)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constructs a new <code>WeakHashMap</code> with the same mappings as the specified <tt>Map</tt>.</TD></TR></TABLE>&nbsp;<!-- ========== METHOD SUMMARY =========== --><A NAME="method_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Method Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;void</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/util/WeakHashMap.html#clear()">clear</A></B>()</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Removes all mappings from this map.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;boolean</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/util/WeakHashMap.html#containsKey(java.lang.Object)">containsKey</A></B>(<A HREF="../../java/lang/Object.html">Object</A>&nbsp;key)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns <code>true</code> if this map contains a mapping for the specified key.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;<A HREF="../../java/util/Set.html">Set</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../java/util/WeakHashMap.html#entrySet()">entrySet</A></B>()</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns a <code>Set</code> view of the mappings in this map.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;<A HREF="../../java/lang/Object.html">Object</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../java/util/WeakHashMap.html#get(java.lang.Object)">get</A></B>(<A HREF="../../java/lang/Object.html">Object</A>&nbsp;key)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the value to which this map maps the specified <code>key</code>.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;boolean</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/util/WeakHashMap.html#isEmpty()">isEmpty</A></B>()</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns <code>true</code> if this map contains no key-value mappings.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;<A HREF="../../java/lang/Object.html">Object</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../java/util/WeakHashMap.html#put(java.lang.Object, java.lang.Object)">put</A></B>(<A HREF="../../java/lang/Object.html">Object</A>&nbsp;key,    <A HREF="../../java/lang/Object.html">Object</A>&nbsp;value)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Updates this map so that the given <code>key</code> maps to the given <code>value</code>.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;<A HREF="../../java/lang/Object.html">Object</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../java/util/WeakHashMap.html#remove(java.lang.Object)">remove</A></B>(<A HREF="../../java/lang/Object.html">Object</A>&nbsp;key)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Removes the mapping for the given <code>key</code> from this map, if present.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;int</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/util/WeakHashMap.html#size()">size</A></B>()</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the number of key-value mappings in this map.</TD></TR></TABLE>&nbsp;<A NAME="methods_inherited_from_class_java.util.AbstractMap"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TD><B>Methods inherited from class java.util.<A HREF="../../java/util/AbstractMap.html">AbstractMap</A></B></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor">

⌨️ 快捷键说明

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