src/share/classes/java/util/List.java

Print this page
rev 3977 : 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.


 117      * @return the number of elements in this list
 118      */
 119     int size();
 120 
 121     /**
 122      * Returns <tt>true</tt> if this list contains no elements.
 123      *
 124      * @return <tt>true</tt> if this list contains no elements
 125      */
 126     boolean isEmpty();
 127 
 128     /**
 129      * Returns <tt>true</tt> if this list contains the specified element.
 130      * More formally, returns <tt>true</tt> if and only if this list contains
 131      * at least one element <tt>e</tt> such that
 132      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
 133      *
 134      * @param o element whose presence in this list is to be tested
 135      * @return <tt>true</tt> if this list contains the specified element
 136      * @throws ClassCastException if the type of the specified element
 137      *         is incompatible with this list (optional)

 138      * @throws NullPointerException if the specified element is null and this
 139      *         list does not permit null elements (optional)

 140      */
 141     boolean contains(Object o);
 142 
 143     /**
 144      * Returns an iterator over the elements in this list in proper sequence.
 145      *
 146      * @return an iterator over the elements in this list in proper sequence
 147      */
 148     Iterator<E> iterator();
 149 
 150     /**
 151      * Returns an array containing all of the elements in this list in proper
 152      * sequence (from first to last element).
 153      *
 154      * <p>The returned array will be "safe" in that no references to it are
 155      * maintained by this list.  (In other words, this method must
 156      * allocate a new array even if this list is backed by an array).
 157      * The caller is thus free to modify the returned array.
 158      *
 159      * <p>This method acts as bridge between array-based and collection-based


 228      * @throws NullPointerException if the specified element is null and this
 229      *         list does not permit null elements
 230      * @throws IllegalArgumentException if some property of this element
 231      *         prevents it from being added to this list
 232      */
 233     boolean add(E e);
 234 
 235     /**
 236      * Removes the first occurrence of the specified element from this list,
 237      * if it is present (optional operation).  If this list does not contain
 238      * the element, it is unchanged.  More formally, removes the element with
 239      * the lowest index <tt>i</tt> such that
 240      * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>
 241      * (if such an element exists).  Returns <tt>true</tt> if this list
 242      * contained the specified element (or equivalently, if this list changed
 243      * as a result of the call).
 244      *
 245      * @param o element to be removed from this list, if present
 246      * @return <tt>true</tt> if this list contained the specified element
 247      * @throws ClassCastException if the type of the specified element
 248      *         is incompatible with this list (optional)

 249      * @throws NullPointerException if the specified element is null and this
 250      *         list does not permit null elements (optional)

 251      * @throws UnsupportedOperationException if the <tt>remove</tt> operation
 252      *         is not supported by this list
 253      */
 254     boolean remove(Object o);
 255 
 256 
 257     // Bulk Modification Operations
 258 
 259     /**
 260      * Returns <tt>true</tt> if this list contains all of the elements of the
 261      * specified collection.
 262      *
 263      * @param  c collection to be checked for containment in this list
 264      * @return <tt>true</tt> if this list contains all of the elements of the
 265      *         specified collection
 266      * @throws ClassCastException if the types of one or more elements
 267      *         in the specified collection are incompatible with this
 268      *         list (optional)

 269      * @throws NullPointerException if the specified collection contains one
 270      *         or more null elements and this list does not permit null
 271      *         elements (optional), or if the specified collection is null


 272      * @see #contains(Object)
 273      */
 274     boolean containsAll(Collection<?> c);
 275 
 276     /**
 277      * Appends all of the elements in the specified collection to the end of
 278      * this list, in the order that they are returned by the specified
 279      * collection's iterator (optional operation).  The behavior of this
 280      * operation is undefined if the specified collection is modified while
 281      * the operation is in progress.  (Note that this will occur if the
 282      * specified collection is this list, and it's nonempty.)
 283      *
 284      * @param c collection containing elements to be added to this list
 285      * @return <tt>true</tt> if this list changed as a result of the call
 286      * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
 287      *         is not supported by this list
 288      * @throws ClassCastException if the class of an element of the specified
 289      *         collection prevents it from being added to this list
 290      * @throws NullPointerException if the specified collection contains one
 291      *         or more null elements and this list does not permit null


 317      *         collection prevents it from being added to this list
 318      * @throws NullPointerException if the specified collection contains one
 319      *         or more null elements and this list does not permit null
 320      *         elements, or if the specified collection is null
 321      * @throws IllegalArgumentException if some property of an element of the
 322      *         specified collection prevents it from being added to this list
 323      * @throws IndexOutOfBoundsException if the index is out of range
 324      *         (<tt>index &lt; 0 || index &gt; size()</tt>)
 325      */
 326     boolean addAll(int index, Collection<? extends E> c);
 327 
 328     /**
 329      * Removes from this list all of its elements that are contained in the
 330      * specified collection (optional operation).
 331      *
 332      * @param c collection containing elements to be removed from this list
 333      * @return <tt>true</tt> if this list changed as a result of the call
 334      * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation
 335      *         is not supported by this list
 336      * @throws ClassCastException if the class of an element of this list
 337      *         is incompatible with the specified collection (optional)

 338      * @throws NullPointerException if this list contains a null element and the
 339      *         specified collection does not permit null elements (optional),

 340      *         or if the specified collection is null
 341      * @see #remove(Object)
 342      * @see #contains(Object)
 343      */
 344     boolean removeAll(Collection<?> c);
 345 
 346     /**
 347      * Retains only the elements in this list that are contained in the
 348      * specified collection (optional operation).  In other words, removes
 349      * from this list all of its elements that are not contained in the
 350      * specified collection.
 351      *
 352      * @param c collection containing elements to be retained in this list
 353      * @return <tt>true</tt> if this list changed as a result of the call
 354      * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
 355      *         is not supported by this list
 356      * @throws ClassCastException if the class of an element of this list
 357      *         is incompatible with the specified collection (optional)

 358      * @throws NullPointerException if this list contains a null element and the
 359      *         specified collection does not permit null elements (optional),

 360      *         or if the specified collection is null
 361      * @see #remove(Object)
 362      * @see #contains(Object)
 363      */
 364     boolean retainAll(Collection<?> c);
 365 
 366     /**
 367      * Removes all of the elements from this list (optional operation).
 368      * The list will be empty after this call returns.
 369      *
 370      * @throws UnsupportedOperationException if the <tt>clear</tt> operation
 371      *         is not supported by this list
 372      */
 373     void clear();
 374 
 375 
 376     // Comparison and hashing
 377 
 378     /**
 379      * Compares the specified object with this list for equality.  Returns


 476      *         is not supported by this list
 477      * @throws IndexOutOfBoundsException if the index is out of range
 478      *         (<tt>index &lt; 0 || index &gt;= size()</tt>)
 479      */
 480     E remove(int index);
 481 
 482 
 483     // Search Operations
 484 
 485     /**
 486      * Returns the index of the first occurrence of the specified element
 487      * in this list, or -1 if this list does not contain the element.
 488      * More formally, returns the lowest index <tt>i</tt> such that
 489      * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
 490      * or -1 if there is no such index.
 491      *
 492      * @param o element to search for
 493      * @return the index of the first occurrence of the specified element in
 494      *         this list, or -1 if this list does not contain the element
 495      * @throws ClassCastException if the type of the specified element
 496      *         is incompatible with this list (optional)

 497      * @throws NullPointerException if the specified element is null and this
 498      *         list does not permit null elements (optional)

 499      */
 500     int indexOf(Object o);
 501 
 502     /**
 503      * Returns the index of the last occurrence of the specified element
 504      * in this list, or -1 if this list does not contain the element.
 505      * More formally, returns the highest index <tt>i</tt> such that
 506      * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
 507      * or -1 if there is no such index.
 508      *
 509      * @param o element to search for
 510      * @return the index of the last occurrence of the specified element in
 511      *         this list, or -1 if this list does not contain the element
 512      * @throws ClassCastException if the type of the specified element
 513      *         is incompatible with this list (optional)

 514      * @throws NullPointerException if the specified element is null and this
 515      *         list does not permit null elements (optional)

 516      */
 517     int lastIndexOf(Object o);
 518 
 519 
 520     // List Iterators
 521 
 522     /**
 523      * Returns a list iterator over the elements in this list (in proper
 524      * sequence).
 525      *
 526      * @return a list iterator over the elements in this list (in proper
 527      *         sequence)
 528      */
 529     ListIterator<E> listIterator();
 530 
 531     /**
 532      * Returns a list iterator over the elements in this list (in proper
 533      * sequence), starting at the specified position in the list.
 534      * The specified index indicates the first element that would be
 535      * returned by an initial call to {@link ListIterator#next next}.




 117      * @return the number of elements in this list
 118      */
 119     int size();
 120 
 121     /**
 122      * Returns <tt>true</tt> if this list contains no elements.
 123      *
 124      * @return <tt>true</tt> if this list contains no elements
 125      */
 126     boolean isEmpty();
 127 
 128     /**
 129      * Returns <tt>true</tt> if this list contains the specified element.
 130      * More formally, returns <tt>true</tt> if and only if this list contains
 131      * at least one element <tt>e</tt> such that
 132      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
 133      *
 134      * @param o element whose presence in this list is to be tested
 135      * @return <tt>true</tt> if this list contains the specified element
 136      * @throws ClassCastException if the type of the specified element
 137      *         is incompatible with this list
 138      * (<a href="Collection.html#optional-restrictions">optional</a>)
 139      * @throws NullPointerException if the specified element is null and this
 140      *         list does not permit null elements
 141      * (<a href="Collection.html#optional-restrictions">optional</a>)
 142      */
 143     boolean contains(Object o);
 144 
 145     /**
 146      * Returns an iterator over the elements in this list in proper sequence.
 147      *
 148      * @return an iterator over the elements in this list in proper sequence
 149      */
 150     Iterator<E> iterator();
 151 
 152     /**
 153      * Returns an array containing all of the elements in this list in proper
 154      * sequence (from first to last element).
 155      *
 156      * <p>The returned array will be "safe" in that no references to it are
 157      * maintained by this list.  (In other words, this method must
 158      * allocate a new array even if this list is backed by an array).
 159      * The caller is thus free to modify the returned array.
 160      *
 161      * <p>This method acts as bridge between array-based and collection-based


 230      * @throws NullPointerException if the specified element is null and this
 231      *         list does not permit null elements
 232      * @throws IllegalArgumentException if some property of this element
 233      *         prevents it from being added to this list
 234      */
 235     boolean add(E e);
 236 
 237     /**
 238      * Removes the first occurrence of the specified element from this list,
 239      * if it is present (optional operation).  If this list does not contain
 240      * the element, it is unchanged.  More formally, removes the element with
 241      * the lowest index <tt>i</tt> such that
 242      * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>
 243      * (if such an element exists).  Returns <tt>true</tt> if this list
 244      * contained the specified element (or equivalently, if this list changed
 245      * as a result of the call).
 246      *
 247      * @param o element to be removed from this list, if present
 248      * @return <tt>true</tt> if this list contained the specified element
 249      * @throws ClassCastException if the type of the specified element
 250      *         is incompatible with this list
 251      * (<a href="Collection.html#optional-restrictions">optional</a>)
 252      * @throws NullPointerException if the specified element is null and this
 253      *         list does not permit null elements
 254      * (<a href="Collection.html#optional-restrictions">optional</a>)
 255      * @throws UnsupportedOperationException if the <tt>remove</tt> operation
 256      *         is not supported by this list
 257      */
 258     boolean remove(Object o);
 259 
 260 
 261     // Bulk Modification Operations
 262 
 263     /**
 264      * Returns <tt>true</tt> if this list contains all of the elements of the
 265      * specified collection.
 266      *
 267      * @param  c collection to be checked for containment in this list
 268      * @return <tt>true</tt> if this list contains all of the elements of the
 269      *         specified collection
 270      * @throws ClassCastException if the types of one or more elements
 271      *         in the specified collection are incompatible with this
 272      *         list
 273      * (<a href="Collection.html#optional-restrictions">optional</a>)
 274      * @throws NullPointerException if the specified collection contains one
 275      *         or more null elements and this list does not permit null
 276      *         elements
 277      *         (<a href="Collection.html#optional-restrictions">optional</a>),
 278      *         or if the specified collection is null
 279      * @see #contains(Object)
 280      */
 281     boolean containsAll(Collection<?> c);
 282 
 283     /**
 284      * Appends all of the elements in the specified collection to the end of
 285      * this list, in the order that they are returned by the specified
 286      * collection's iterator (optional operation).  The behavior of this
 287      * operation is undefined if the specified collection is modified while
 288      * the operation is in progress.  (Note that this will occur if the
 289      * specified collection is this list, and it's nonempty.)
 290      *
 291      * @param c collection containing elements to be added to this list
 292      * @return <tt>true</tt> if this list changed as a result of the call
 293      * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
 294      *         is not supported by this list
 295      * @throws ClassCastException if the class of an element of the specified
 296      *         collection prevents it from being added to this list
 297      * @throws NullPointerException if the specified collection contains one
 298      *         or more null elements and this list does not permit null


 324      *         collection prevents it from being added to this list
 325      * @throws NullPointerException if the specified collection contains one
 326      *         or more null elements and this list does not permit null
 327      *         elements, or if the specified collection is null
 328      * @throws IllegalArgumentException if some property of an element of the
 329      *         specified collection prevents it from being added to this list
 330      * @throws IndexOutOfBoundsException if the index is out of range
 331      *         (<tt>index &lt; 0 || index &gt; size()</tt>)
 332      */
 333     boolean addAll(int index, Collection<? extends E> c);
 334 
 335     /**
 336      * Removes from this list all of its elements that are contained in the
 337      * specified collection (optional operation).
 338      *
 339      * @param c collection containing elements to be removed from this list
 340      * @return <tt>true</tt> if this list changed as a result of the call
 341      * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation
 342      *         is not supported by this list
 343      * @throws ClassCastException if the class of an element of this list
 344      *         is incompatible with the specified collection
 345      * (<a href="Collection.html#optional-restrictions">optional</a>)
 346      * @throws NullPointerException if this list contains a null element and the
 347      *         specified collection does not permit null elements
 348      *         (<a href="Collection.html#optional-restrictions">optional</a>),
 349      *         or if the specified collection is null
 350      * @see #remove(Object)
 351      * @see #contains(Object)
 352      */
 353     boolean removeAll(Collection<?> c);
 354 
 355     /**
 356      * Retains only the elements in this list that are contained in the
 357      * specified collection (optional operation).  In other words, removes
 358      * from this list all of its elements that are not contained in the
 359      * specified collection.
 360      *
 361      * @param c collection containing elements to be retained in this list
 362      * @return <tt>true</tt> if this list changed as a result of the call
 363      * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
 364      *         is not supported by this list
 365      * @throws ClassCastException if the class of an element of this list
 366      *         is incompatible with the specified collection
 367      * (<a href="Collection.html#optional-restrictions">optional</a>)
 368      * @throws NullPointerException if this list contains a null element and the
 369      *         specified collection does not permit null elements
 370      *         (<a href="Collection.html#optional-restrictions">optional</a>),
 371      *         or if the specified collection is null
 372      * @see #remove(Object)
 373      * @see #contains(Object)
 374      */
 375     boolean retainAll(Collection<?> c);
 376 
 377     /**
 378      * Removes all of the elements from this list (optional operation).
 379      * The list will be empty after this call returns.
 380      *
 381      * @throws UnsupportedOperationException if the <tt>clear</tt> operation
 382      *         is not supported by this list
 383      */
 384     void clear();
 385 
 386 
 387     // Comparison and hashing
 388 
 389     /**
 390      * Compares the specified object with this list for equality.  Returns


 487      *         is not supported by this list
 488      * @throws IndexOutOfBoundsException if the index is out of range
 489      *         (<tt>index &lt; 0 || index &gt;= size()</tt>)
 490      */
 491     E remove(int index);
 492 
 493 
 494     // Search Operations
 495 
 496     /**
 497      * Returns the index of the first occurrence of the specified element
 498      * in this list, or -1 if this list does not contain the element.
 499      * More formally, returns the lowest index <tt>i</tt> such that
 500      * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
 501      * or -1 if there is no such index.
 502      *
 503      * @param o element to search for
 504      * @return the index of the first occurrence of the specified element in
 505      *         this list, or -1 if this list does not contain the element
 506      * @throws ClassCastException if the type of the specified element
 507      *         is incompatible with this list
 508      *         (<a href="Collection.html#optional-restrictions">optional</a>)
 509      * @throws NullPointerException if the specified element is null and this
 510      *         list does not permit null elements
 511      *         (<a href="Collection.html#optional-restrictions">optional</a>)
 512      */
 513     int indexOf(Object o);
 514 
 515     /**
 516      * Returns the index of the last occurrence of the specified element
 517      * in this list, or -1 if this list does not contain the element.
 518      * More formally, returns the highest index <tt>i</tt> such that
 519      * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
 520      * or -1 if there is no such index.
 521      *
 522      * @param o element to search for
 523      * @return the index of the last occurrence of the specified element in
 524      *         this list, or -1 if this list does not contain the element
 525      * @throws ClassCastException if the type of the specified element
 526      *         is incompatible with this list
 527      *         (<a href="Collection.html#optional-restrictions">optional</a>)
 528      * @throws NullPointerException if the specified element is null and this
 529      *         list does not permit null elements
 530      *         (<a href="Collection.html#optional-restrictions">optional</a>)
 531      */
 532     int lastIndexOf(Object o);
 533 
 534 
 535     // List Iterators
 536 
 537     /**
 538      * Returns a list iterator over the elements in this list (in proper
 539      * sequence).
 540      *
 541      * @return a list iterator over the elements in this list (in proper
 542      *         sequence)
 543      */
 544     ListIterator<E> listIterator();
 545 
 546     /**
 547      * Returns a list iterator over the elements in this list (in proper
 548      * sequence), starting at the specified position in the list.
 549      * The specified index indicates the first element that would be
 550      * returned by an initial call to {@link ListIterator#next next}.