📄 treemap.html
字号:
<!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:02 PDT 2000 --><TITLE>Java 2 Platform SE v1.3: Class TreeMap</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> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/TreeMap.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><b>Java<sup><font size=-2>TM</font></sup> 2 Platform<br>Std. Ed. v1.3</b></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../java/util/TimeZone.html"><B>PREV CLASS</B></A> <A HREF="../../java/util/TreeSet.html"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../index.html" TARGET="_top"><B>FRAMES</B></A> <A HREF="TreeMap.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: INNER | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <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 TreeMap</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.TreeMap</B></PRE><DL><DT><B>All Implemented Interfaces:</B> <DD><A HREF="../../java/lang/Cloneable.html">Cloneable</A>, <A HREF="../../java/util/Map.html">Map</A>, <A HREF="../../java/io/Serializable.html">Serializable</A>, <A HREF="../../java/util/SortedMap.html">SortedMap</A></DD></DL><HR><DL><DT>public class <B>TreeMap</B><DT>extends <A HREF="../../java/util/AbstractMap.html">AbstractMap</A><DT>implements <A HREF="../../java/util/SortedMap.html">SortedMap</A>, <A HREF="../../java/lang/Cloneable.html">Cloneable</A>, <A HREF="../../java/io/Serializable.html">Serializable</A></DL><P>Red-Black tree based implementation of the <tt>SortedMap</tt> interface. This class guarantees that the map will be in ascending key order, sorted according to the <i>natural order</i> for the key's class (see <tt>Comparable</tt>), or by the comparator provided at creation time, depending on which constructor is used.<p> This implementation provides guaranteed log(n) time cost for the <tt>containsKey</tt>, <tt>get</tt>, <tt>put</tt> and <tt>remove</tt> operations. Algorithms are adaptations of those in Cormen, Leiserson, and Rivest's <I>Introduction to Algorithms</I>.<p> Note that the ordering maintained by a sorted map (whether or not an explicit comparator is provided) must be <i>consistent with equals</i> if this sorted map is to correctly implement the <tt>Map</tt> interface. (See <tt>Comparable</tt> or <tt>Comparator</tt> for a precise definition of <i>consistent with equals</i>.) This is so because the <tt>Map</tt> interface is defined in terms of the equals operation, but a map performs all key comparisons using its <tt>compareTo</tt> (or <tt>compare</tt>) method, so two keys that are deemed equal by this method are, from the standpoint of the sorted map, equal. The behavior of a sorted map <i>is</i> well-defined even if its ordering is inconsistent with equals; it just fails to obey the general contract of the <tt>Map</tt> interface.<p> <b>Note that this implementation is not synchronized.</b> If multiple threads access a map concurrently, and at least one of the threads modifies the map structurally, it <i>must</i> be synchronized externally. (A structural modification is any operation that adds or deletes one or more mappings; merely changing the value associated with an existing key is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the map. If no such object exists, the map should be "wrapped" using the <tt>Collections.synchronizedMap</tt> method. This is best done at creation time, to prevent accidental unsynchronized access to the map: <pre> Map m = Collections.synchronizedMap(new TreeMap(...)); </pre><p> The iterators returned by all of this class's "collection view methods" are <i>fail-fast</i>: if the map is structurally modified at any time after the iterator is created, in any way except through the iterator's own <tt>remove</tt> or <tt>add</tt> methods, the iterator throws a <tt>ConcurrentModificationException</tt>. 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.<P><DL><DT><B>Since: </B><DD>1.2</DD><DT><B>See Also: </B><DD><A HREF="../../java/util/Map.html"><CODE>Map</CODE></A>, <A HREF="../../java/util/HashMap.html"><CODE>HashMap</CODE></A>, <A HREF="../../java/util/Hashtable.html"><CODE>Hashtable</CODE></A>, <A HREF="../../java/lang/Comparable.html"><CODE>Comparable</CODE></A>, <A HREF="../../java/util/Comparator.html"><CODE>Comparator</CODE></A>, <A HREF="../../java/util/Collection.html"><CODE>Collection</CODE></A>, <A HREF="../../java/util/Collections.html#synchronizedMap(java.util.Map)"><CODE>Collections.synchronizedMap(Map)</CODE></A>, <A HREF="../../serialized-form.html#java.util.TreeMap">Serialized Form</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> <!-- =========== 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/TreeMap.html#TreeMap()">TreeMap</A></B>()</CODE><BR> Constructs a new, empty map, sorted according to the keys' natural order.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../java/util/TreeMap.html#TreeMap(java.util.Comparator)">TreeMap</A></B>(<A HREF="../../java/util/Comparator.html">Comparator</A> c)</CODE><BR> Constructs a new, empty map, sorted according to the given comparator.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../java/util/TreeMap.html#TreeMap(java.util.Map)">TreeMap</A></B>(<A HREF="../../java/util/Map.html">Map</A> m)</CODE><BR> Constructs a new map containing the same mappings as the given map, sorted according to the keys' <i>natural order</i>.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../java/util/TreeMap.html#TreeMap(java.util.SortedMap)">TreeMap</A></B>(<A HREF="../../java/util/SortedMap.html">SortedMap</A> m)</CODE><BR> Constructs a new map containing the same mappings as the given <tt>SortedMap</tt>, sorted according to the same ordering.</TD></TR></TABLE> <!-- ========== 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> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/util/TreeMap.html#clear()">clear</A></B>()</CODE><BR> Removes all mappings from this TreeMap.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../java/lang/Object.html">Object</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../java/util/TreeMap.html#clone()">clone</A></B>()</CODE><BR> Returns a shallow copy of this <tt>TreeMap</tt> instance.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../java/util/Comparator.html">Comparator</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../java/util/TreeMap.html#comparator()">comparator</A></B>()</CODE><BR> Returns the comparator used to order this map, or <tt>null</tt> if this map uses its keys' natural order.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> boolean</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/util/TreeMap.html#containsKey(java.lang.Object)">containsKey</A></B>(<A HREF="../../java/lang/Object.html">Object</A> key)</CODE><BR> Returns <tt>true</tt> 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> boolean</CODE></FONT></TD>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -