📄 sortedset.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:36:45 PDT 2000 --><TITLE>Java 2 Platform SE v1.3: Interface SortedSet</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/SortedSet.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/SortedMap.html"><B>PREV CLASS</B></A> NEXT CLASS</FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../index.html" TARGET="_top"><B>FRAMES</B></A> <A HREF="SortedSet.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: INNER | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: FIELD | CONSTR | <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>Interface SortedSet</H2><DL><DT><B>All Superinterfaces:</B> <DD><A HREF="../../java/util/Collection.html">Collection</A>, <A HREF="../../java/util/Set.html">Set</A></DD></DL><DL><DT><B>All Known Implementing Classes:</B> <DD><A HREF="../../java/util/TreeSet.html">TreeSet</A></DD></DL><HR><DL><DT>public interface <B>SortedSet</B><DT>extends <A HREF="../../java/util/Set.html">Set</A></DL><P>A set that further guarantees that its iterator will traverse the set in ascending element order, sorted according to the <i>natural ordering</i> of its elements (see Comparable), or by a Comparator provided at sorted set creation time. Several additional operations are provided to take advantage of the ordering. (This interface is the set analogue of SortedMap.)<p> All elements inserted into an sorted set must implement the Comparable interface (or be accepted by the specified Comparator). Furthermore, all such elements must be <i>mutually comparable</i>: <tt>e1.compareTo(e2)</tt> (or <tt>comparator.compare(e1, e2)</tt>) must not throw a <tt>ClassCastException</tt> for any elements <tt>e1</tt> and <tt>e2</tt> in the sorted set. Attempts to violate this restriction will cause the offending method or constructor invocation to throw a <tt>ClassCastException</tt>.<p> Note that the ordering maintained by a sorted set (whether or not an explicit comparator is provided) must be <i>consistent with equals</i> if the sorted set is to correctly implement the <tt>Set</tt> interface. (See the <tt>Comparable</tt> interface or <tt>Comparator</tt> interface for a precise definition of <i>consistent with equals</i>.) This is so because the <tt>Set</tt> interface is defined in terms of the <tt>equals</tt> operation, but a sorted set performs all element comparisons using its <tt>compareTo</tt> (or <tt>compare</tt>) method, so two elements that are deemed equal by this method are, from the standpoint of the sorted set, equal. The behavior of a sorted set <i>is</i> well-defined even if its ordering is inconsistent with equals; it just fails to obey the general contract of the <tt>Set</tt> interface.<p> All general-purpose sorted set implementation classes should provide four "standard" constructors: 1) A void (no arguments) constructor, which creates an empty sorted set sorted according to the <i>natural order</i> of its elements. 2) A constructor with a single argument of type <tt>Comparator</tt>, which creates an empty sorted set sorted according to the specified comparator. 3) A constructor with a single argument of type <tt>Collection</tt>, which creates a new sorted set with the same elements as its argument, sorted according to the elements' natural ordering. 4) A constructor with a single argument of type <tt>SortedSet</tt>, which creates a new sorted set with the same elements and the same ordering as the input sorted set. There is no way to enforce this recommendation (as interfaces cannot contain constructors) but the SDK implementation (the <tt>TreeSet</tt> class) complies.<P><DL><DT><B>Since: </B><DD>1.2</DD><DT><B>See Also: </B><DD><A HREF="../../java/util/Set.html"><CODE>Set</CODE></A>, <A HREF="../../java/util/TreeSet.html"><CODE>TreeSet</CODE></A>, <A HREF="../../java/util/SortedMap.html"><CODE>SortedMap</CODE></A>, <A HREF="../../java/util/Collection.html"><CODE>Collection</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/lang/ClassCastException.html"><CODE>ClassCastException</CODE></A></DL><HR><P><!-- ======== INNER CLASS SUMMARY ======== --><!-- =========== FIELD SUMMARY =========== --><!-- ======== CONSTRUCTOR SUMMARY ======== --><!-- ========== 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> <A HREF="../../java/util/Comparator.html">Comparator</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../java/util/SortedSet.html#comparator()">comparator</A></B>()</CODE><BR> Returns the comparator associated with this sorted set, or <tt>null</tt> if it uses its elements' natural ordering.</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/SortedSet.html#first()">first</A></B>()</CODE><BR> Returns the first (lowest) element currently in this sorted set.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../java/util/SortedSet.html">SortedSet</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../java/util/SortedSet.html#headSet(java.lang.Object)">headSet</A></B>(<A HREF="../../java/lang/Object.html">Object</A> toElement)</CODE><BR> Returns a view of the portion of this sorted set whose elements are strictly less than <tt>toElement</tt>.</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/SortedSet.html#last()">last</A></B>()</CODE><BR> Returns the last (highest) element currently in this sorted set.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../java/util/SortedSet.html">SortedSet</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../java/util/SortedSet.html#subSet(java.lang.Object, java.lang.Object)">subSet</A></B>(<A HREF="../../java/lang/Object.html">Object</A> fromElement, <A HREF="../../java/lang/Object.html">Object</A> toElement)</CODE><BR> Returns a view of the portion of this sorted set whose elements range from <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>, exclusive.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../java/util/SortedSet.html">SortedSet</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../java/util/SortedSet.html#tailSet(java.lang.Object)">tailSet</A></B>(<A HREF="../../java/lang/Object.html">Object</A> fromElement)</CODE><BR> Returns a view of the portion of this sorted set whose elements are greater than or equal to <tt>fromElement</tt>.</TD></TR></TABLE> <A NAME="methods_inherited_from_class_java.util.Set"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TD><B>Methods inherited from interface java.util.<A HREF="../../java/util/Set.html">Set</A></B></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><A HREF="../../java/util/Set.html#add(java.lang.Object)">add</A>, <A HREF="../../java/util/Set.html#addAll(java.util.Collection)">addAll</A>, <A HREF="../../java/util/Set.html#clear()">clear</A>, <A HREF="../../java/util/Set.html#contains(java.lang.Object)">contains</A>, <A HREF="../../java/util/Set.html#containsAll(java.util.Collection)">containsAll</A>, <A HREF="../../java/util/Set.html#equals(java.lang.Object)">equals</A>, <A HREF="../../java/util/Set.html#hashCode()">hashCode</A>, <A HREF="../../java/util/Set.html#isEmpty()">isEmpty</A>, <A HREF="../../java/util/Set.html#iterator()">iterator</A>, <A HREF="../../java/util/Set.html#remove(java.lang.Object)">remove</A>, <A HREF="../../java/util/Set.html#removeAll(java.util.Collection)">removeAll</A>, <A HREF="../../java/util/Set.html#retainAll(java.util.Collection)">retainAll</A>, <A HREF="../../java/util/Set.html#size()">size</A>, <A HREF="../../java/util/Set.html#toArray()">toArray</A>, <A HREF="../../java/util/Set.html#toArray(java.lang.Object[])">toArray</A></CODE></TD></TR></TABLE> <P><!-- ============ FIELD DETAIL =========== --><!-- ========= CONSTRUCTOR DETAIL ======== --><!-- ============ METHOD DETAIL ========== --><A NAME="method_detail"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=1><FONT SIZE="+2"><B>Method Detail</B></FONT></TD></TR></TABLE><A NAME="comparator()"><!-- --></A><H3>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -