src/share/classes/java/util/ArrayList.java

Print this page
rev 4788 : Fix bunch of generics warnings


 283         if (o == null) {
 284             for (int i = size-1; i >= 0; i--)
 285                 if (elementData[i]==null)
 286                     return i;
 287         } else {
 288             for (int i = size-1; i >= 0; i--)
 289                 if (o.equals(elementData[i]))
 290                     return i;
 291         }
 292         return -1;
 293     }
 294 
 295     /**
 296      * Returns a shallow copy of this <tt>ArrayList</tt> instance.  (The
 297      * elements themselves are not copied.)
 298      *
 299      * @return a clone of this <tt>ArrayList</tt> instance
 300      */
 301     public Object clone() {
 302         try {
 303             @SuppressWarnings("unchecked")
 304                 ArrayList<E> v = (ArrayList<E>) super.clone();
 305             v.elementData = Arrays.copyOf(elementData, size);
 306             v.modCount = 0;
 307             return v;
 308         } catch (CloneNotSupportedException e) {
 309             // this shouldn't happen, since we are Cloneable
 310             throw new InternalError(e);
 311         }
 312     }
 313 
 314     /**
 315      * Returns an array containing all of the elements in this list
 316      * in proper sequence (from first to last element).
 317      *
 318      * <p>The returned array will be "safe" in that no references to it are
 319      * maintained by this list.  (In other words, this method must allocate
 320      * a new array).  The caller is thus free to modify the returned array.
 321      *
 322      * <p>This method acts as bridge between array-based and collection-based
 323      * APIs.
 324      *




 283         if (o == null) {
 284             for (int i = size-1; i >= 0; i--)
 285                 if (elementData[i]==null)
 286                     return i;
 287         } else {
 288             for (int i = size-1; i >= 0; i--)
 289                 if (o.equals(elementData[i]))
 290                     return i;
 291         }
 292         return -1;
 293     }
 294 
 295     /**
 296      * Returns a shallow copy of this <tt>ArrayList</tt> instance.  (The
 297      * elements themselves are not copied.)
 298      *
 299      * @return a clone of this <tt>ArrayList</tt> instance
 300      */
 301     public Object clone() {
 302         try {
 303             ArrayList<?> v = (ArrayList<?>) super.clone();

 304             v.elementData = Arrays.copyOf(elementData, size);
 305             v.modCount = 0;
 306             return v;
 307         } catch (CloneNotSupportedException e) {
 308             // this shouldn't happen, since we are Cloneable
 309             throw new InternalError(e);
 310         }
 311     }
 312 
 313     /**
 314      * Returns an array containing all of the elements in this list
 315      * in proper sequence (from first to last element).
 316      *
 317      * <p>The returned array will be "safe" in that no references to it are
 318      * maintained by this list.  (In other words, this method must allocate
 319      * a new array).  The caller is thus free to modify the returned array.
 320      *
 321      * <p>This method acts as bridge between array-based and collection-based
 322      * APIs.
 323      *