📄 collection.html
字号:
collection, if it is present (optional operation).</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/Collection.html#removeAll(java.util.Collection)">removeAll</A></B>(<A HREF="../../java/util/Collection.html">Collection</A> c)</CODE><BR> Removes all this collection's elements that are also contained in the specified collection (optional operation).</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/Collection.html#retainAll(java.util.Collection)">retainAll</A></B>(<A HREF="../../java/util/Collection.html">Collection</A> c)</CODE><BR> Retains only the elements in this collection that are contained in the specified collection (optional operation).</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> int</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/util/Collection.html#size()">size</A></B>()</CODE><BR> Returns the number of elements in this collection.</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/Collection.html#toArray()">toArray</A></B>()</CODE><BR> Returns an array containing all of the elements in this collection.</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/Collection.html#toArray(java.lang.Object[])">toArray</A></B>(<A HREF="../../java/lang/Object.html">Object</A>[] a)</CODE><BR> Returns an array containing all of the elements in this collection whose runtime type is that of the specified array.</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="size()"><!-- --></A><H3>size</H3><PRE>public int <B>size</B>()</PRE><DL><DD>Returns the number of elements in this collection. If this collection contains more than <tt>Integer.MAX_VALUE</tt> elements, returns <tt>Integer.MAX_VALUE</tt>.<DD><DL><DT><B>Returns:</B><DD>the number of elements in this collection</DL></DD></DL><HR><A NAME="isEmpty()"><!-- --></A><H3>isEmpty</H3><PRE>public boolean <B>isEmpty</B>()</PRE><DL><DD>Returns <tt>true</tt> if this collection contains no elements.<DD><DL><DT><B>Returns:</B><DD><tt>true</tt> if this collection contains no elements</DL></DD></DL><HR><A NAME="contains(java.lang.Object)"><!-- --></A><H3>contains</H3><PRE>public boolean <B>contains</B>(<A HREF="../../java/lang/Object.html">Object</A> o)</PRE><DL><DD>Returns <tt>true</tt> if this collection contains the specified element. More formally, returns <tt>true</tt> if and only if this collection contains at least one element <tt>e</tt> such that <tt>(o==null ? e==null : o.equals(e))</tt>.<DD><DL><DT><B>Parameters:</B><DD><CODE>o</CODE> - element whose presence in this collection is to be tested.<DT><B>Returns:</B><DD><tt>true</tt> if this collection contains the specified element</DL></DD></DL><HR><A NAME="iterator()"><!-- --></A><H3>iterator</H3><PRE>public <A HREF="../../java/util/Iterator.html">Iterator</A> <B>iterator</B>()</PRE><DL><DD>Returns an iterator over the elements in this collection. There are no guarantees concerning the order in which the elements are returned (unless this collection is an instance of some class that provides a guarantee).<DD><DL><DT><B>Returns:</B><DD>an <tt>Iterator</tt> over the elements in this collection</DL></DD></DL><HR><A NAME="toArray()"><!-- --></A><H3>toArray</H3><PRE>public <A HREF="../../java/lang/Object.html">Object</A>[] <B>toArray</B>()</PRE><DL><DD>Returns an array containing all of the elements in this collection. If the collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.<p> The returned array will be "safe" in that no references to it are maintained by this collection. (In other words, this method must allocate a new array even if this collection is backed by an array). The caller is thus free to modify the returned array.<p> This method acts as bridge between array-based and collection-based APIs.<DD><DL><DT><B>Returns:</B><DD>an array containing all of the elements in this collection</DL></DD></DL><HR><A NAME="toArray(java.lang.Object[])"><!-- --></A><H3>toArray</H3><PRE>public <A HREF="../../java/lang/Object.html">Object</A>[] <B>toArray</B>(<A HREF="../../java/lang/Object.html">Object</A>[] a)</PRE><DL><DD>Returns an array containing all of the elements in this collection whose runtime type is that of the specified array. If the collection fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this collection.<p> If this collection fits in the specified array with room to spare (i.e., the array has more elements than this collection), the element in the array immediately following the end of the collection is set to <tt>null</tt>. This is useful in determining the length of this collection <i>only</i> if the caller knows that this collection does not contain any <tt>null</tt> elements.)<p> If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.<p> Like the <tt>toArray</tt> method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs<p> Suppose <tt>l</tt> is a <tt>List</tt> known to contain only strings. The following code can be used to dump the list into a newly allocated array of <tt>String</tt>: <pre> String[] x = (String[]) v.toArray(new String[0]); </pre><p> Note that <tt>toArray(new Object[0])</tt> is identical in function to <tt>toArray()</tt>.<DD><DL><DT><B>Parameters:</B><DD><CODE>a</CODE> - the array into which the elements of this collection are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.<DT><B>Returns:</B><DD>an array containing the elements of this collection<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/ArrayStoreException.html">ArrayStoreException</A></CODE> - the runtime type of the specified array is not a supertype of the runtime type of every element in this collection.</DL></DD></DL><HR><A NAME="add(java.lang.Object)"><!-- --></A><H3>add</H3><PRE>public boolean <B>add</B>(<A HREF="../../java/lang/Object.html">Object</A> o)</PRE><DL><DD>Ensures that this collection contains the specified element (optional operation). Returns <tt>true</tt> if this collection changed as a result of the call. (Returns <tt>false</tt> if this collection does not permit duplicates and already contains the specified element.)<p> Collections that support this operation may place limitations on what elements may be added to this collection. In particular, some collections will refuse to add <tt>null</tt> elements, and others will impose restrictions on the type of elements that may be added. Collection classes should clearly specify in their documentation any restrictions on what elements may be added.<p> If a collection refuses to add a particular element for any reason other than that it already contains the element, it <i>must</i> throw an exception (rather than returning <tt>false</tt>). This preserves the invariant that a collection always contains the specified element after this call returns.<DD><DL><DT><B>Parameters:</B><DD><CODE>o</CODE> - element whose presence in this collection is to be ensured.<DT><B>Returns:</B><DD><tt>true</tt> if this collection changed as a result of the call<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/UnsupportedOperationException.html">UnsupportedOperationException</A></CODE> - add is not supported by this collection.<DD><CODE><A HREF="../../java/lang/ClassCastException.html">ClassCastException</A></CODE> - class of the specified element prevents it from being added to this collection.<DD><CODE><A HREF="../../java/lang/IllegalArgumentException.html">IllegalArgumentException</A></CODE> - some aspect of this element prevents it from being added to this collection.</DL>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -