Java Reference
In-Depth Information
Display 16.4
Selected Methods in the List<T> Interface (part 2 of 3)
public boolean addAll(Collection<? extends T> collectionToAdd) (Optional )
Adds all of the elements in collectionToAdd to the end of the calling object's list. The elements
are added in the order they are produced by an iterator for collectionToAdd .
public boolean remove(Object element) (Optional)
Removes the first occurrence of element from the calling object's list, if it is present. Returns
true if the calling object contained the element; returns false otherwise.
public boolean removeAll(Collection<?> collectionToRemove) (Optional)
Removes all the calling object's elements that are also in collectionToRemove . Returns true
if the calling object was changed; otherwise returns false .
NEW METHOD HEADINGS
The following methods are in the List<T> interface but were not in the Collection<T>
interface. Those that are optional are noted.
public void add(int index, T newElement) (Optional)
Inserts newElement in the calling object's list at location index . The old elements at location
index and higher are moved to higher indices.
public boolean addAll(int index,
Collection<? extends T> collectionToAdd) (Optional)
Inserts all of the elements in collectionToAdd to the calling object's list starting at location
index . The old elements at location index and higher are moved to higher indices. The elements
are added in the order they are produced by an iterator for collectionToAdd .
public T get(int index)
Returns the object at position index .
public T set(int index, T newElement) (Optional)
Sets the element at the specified index to newElement . The element previously at that position
is returned.
public T remove(int index) (Optional)
Removes the element at position index in the calling object. Shifts any subsequent elements to
the left (subtracts one from their indices). Returns the element that was removed from the calling
object.
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.
(continued)
 
Search WWH ::




Custom Search