Java Reference
In-Depth Information
Display 16.7
Methods in the Classes ArrayList<T> and Vector<T> (part 3 of 4)
public boolean addAll(Collection<? extends T> c)
Appends all the elements in c to the end of the elements in the calling object in the order that they
are enumerated by a c iterator. The behavior of this method is not guaranteed if the collection c is
the calling object or any collection including the calling object either directly or indirectly.
public boolean addAll( int index, Collection<? extends T> c)
Inserts all the elements in c into the calling object starting at position index . Elements are
inserted in the order that they are enumerated by a c iterator. Elements previously at positions
index or higher are shifted to higher numbered positions.
METHODS TO REMOVE ELEMENTS FOR BOTH ArrayList<T> AND Vector<T>
public T remove( int index)
Deletes the element at the specified index and returns the element deleted. The size of the
calling object is decreased by one. The capacity of the calling object is not changed. Each element
in the calling object with an index greater than or equal to index is decreased to have an index
that is one less than the value it had previously.
The index must be a value greater than or equal to zero and less than the size of the calling
object (before this removal).
public boolean remove(Object theElement)
Removes the first occurrence of theElement from the calling object. If theElement is found
in the calling object, then each element in the calling object with an index greater than or equal to
theElement' s index is decreased to have an index that is one less than the value it had previously.
Returns true if theElement was found (and removed). Returns false if theElement is not found in
the calling object. If the element was removed, the size is decreased by one. The capacity is not changed.
protected void removeRange( int fromIndex, int toIndex)
Removes all elements with index greater than or equal to fromIndex and strictly less than
toIndex . Be sure to note that this method is protected , not public .
public void clear()
Removes all elements from the calling object and sets its size to zero.
SEARCH METHODS FOR BOTH ArrayList<T> AND Vector<T>
public boolean isEmpty()
Returns true if the calling object is empty (that is, has size 0 ); otherwise returns false .
public boolean contains(Object target)
Returns true if target is an element of the calling object; otherwise returns false . Uses the
method equals of the object target to test for equality.
public int indexOf(Object target)
Returns the index of the first element that is equal to target . Uses the method equals of the
object target to test for equality. Returns 1 if target is not found.
public int lastIndexOf(Object target)
Returns the index of the last element that is equal to target . Uses the method equals of the
object target to test for equality. Returns 1 if target is not found.
(continued)
 
Search WWH ::




Custom Search