public interface List<E> extends Collection<E>
List is a collection which maintains an ordering for its elements. Every
element in the List has an index. Each element can thus be accessed by its
index, with the first index being zero. Normally, Lists allow duplicate
elements, as compared to Sets, where elements have to be unique.| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E object)
Adds the specified object at the end of this
List. |
void |
add(int location,
E object)
Inserts the specified object into this
List at the specified location. |
boolean |
addAll(Collection<? extends E> collection)
Adds the objects in the specified collection to the end of this
List. |
boolean |
addAll(int location,
Collection<? extends E> collection)
Inserts the objects in the specified collection at the specified location
in this
List. |
void |
clear()
Removes all elements from this
List, leaving it empty. |
boolean |
contains(Object object)
Tests whether this
List contains the specified object. |
boolean |
containsAll(Collection<?> collection)
Tests whether this
List contains all objects contained in the
specified collection. |
boolean |
equals(Object object)
Compares the given object with the
List, and returns true if they
represent the same object using a class specific comparison. |
E |
get(int location)
Returns the element at the specified location in this
List. |
int |
hashCode()
Returns the hash code for this
List. |
int |
indexOf(Object object)
Searches this
List for the specified object and returns the index of the
first occurrence. |
boolean |
isEmpty()
Returns whether this
List contains no elements. |
Iterator<E> |
iterator()
Returns an iterator on the elements of this
List. |
int |
lastIndexOf(Object object)
Searches this
List for the specified object and returns the index of the
last occurrence. |
ListIterator<E> |
listIterator()
Returns a
List iterator on the elements of this List. |
ListIterator<E> |
listIterator(int location)
Returns a list iterator on the elements of this
List. |
E |
remove(int location)
Removes the object at the specified location from this
List. |
boolean |
remove(Object object)
Removes the first occurrence of the specified object from this
List. |
boolean |
removeAll(Collection<?> collection)
Removes all occurrences in this
List of each object in the specified
collection. |
boolean |
retainAll(Collection<?> collection)
Removes all objects from this
List that are not contained in the
specified collection. |
E |
set(int location,
E object)
Replaces the element at the specified location in this
List with the
specified object. |
int |
size()
Returns the number of elements in this
List. |
List<E> |
subList(int start,
int end)
Returns a
List of the specified portion of this List from the given start
index to the end index minus one. |
Object[] |
toArray()
Returns an array containing all elements contained in this
List. |
<T> T[] |
toArray(T[] array)
Returns an array containing all elements contained in this
List. |
void add(int location,
E object)
List at the specified location.
The object is inserted before the current element at the specified
location. If the location is equal to the size of this List, the object
is added at the end. If the location is smaller than the size of this
List, then all elements beyond the specified location are moved by one
position towards the end of the List.location - the index at which to insert.object - the object to add.UnsupportedOperationException - if adding to this List is not supported.ClassCastException - if the class of the object is inappropriate for this
List.IllegalArgumentException - if the object cannot be added to this List.IndexOutOfBoundsException - if location < 0 || location > size()boolean add(E object)
List.add in interface Collection<E>object - the object to add.UnsupportedOperationException - if adding to this List is not supported.ClassCastException - if the class of the object is inappropriate for this
List.IllegalArgumentException - if the object cannot be added to this List.boolean addAll(int location,
Collection<? extends E> collection)
List. The objects are added in the order they are returned from
the collection's iterator.location - the index at which to insert.collection - the collection of objects to be inserted.List has been modified through the insertion, false
otherwise (i.e. if the passed collection was empty).UnsupportedOperationException - if adding to this List is not supported.ClassCastException - if the class of an object is inappropriate for this
List.IllegalArgumentException - if an object cannot be added to this List.IndexOutOfBoundsException - if location < 0 || > size()boolean addAll(Collection<? extends E> collection)
List. The
objects are added in the order in which they are returned from the
collection's iterator.addAll in interface Collection<E>collection - the collection of objects.true if this List is modified, false otherwise
(i.e. if the passed collection was empty).UnsupportedOperationException - if adding to this List is not supported.ClassCastException - if the class of an object is inappropriate for this
List.IllegalArgumentException - if an object cannot be added to this List.void clear()
List, leaving it empty.clear in interface Collection<E>UnsupportedOperationException - if removing from this List is not supported.isEmpty(),
size()boolean contains(Object object)
List contains the specified object.contains in interface Collection<E>object - the object to search for.true if object is an element of this List, false
otherwiseboolean containsAll(Collection<?> collection)
List contains all objects contained in the
specified collection.containsAll in interface Collection<E>collection - the collection of objectstrue if all objects in the specified collection are
elements of this List, false otherwise.boolean equals(Object object)
List, and returns true if they
represent the same object using a class specific comparison. For
Lists, this means that they contain the same elements in exactly the same
order.equals in interface Collection<E>equals in class Objectobject - the object to compare with this object.true if the object is the same as this object,
and false if it is different from this object.hashCode()E get(int location)
List.location - the index of the element to return.IndexOutOfBoundsException - if location < 0 || >= size()int hashCode()
List. It is calculated by taking each
element' hashcode and its position in the List into account.hashCode in interface Collection<E>hashCode in class ObjectList.Collection.equals(java.lang.Object)int indexOf(Object object)
List for the specified object and returns the index of the
first occurrence.object - the object to search for.boolean isEmpty()
List contains no elements.isEmpty in interface Collection<E>true if this List has no elements, false
otherwise.size()Iterator<E> iterator()
List. The elements are
iterated in the same order as they occur in the List.int lastIndexOf(Object object)
List for the specified object and returns the index of the
last occurrence.object - the object to search for.ListIterator<E> listIterator()
List iterator on the elements of this List. The elements are
iterated in the same order that they occur in the List.List iterator on the elements of this ListListIteratorListIterator<E> listIterator(int location)
List. The elements are
iterated in the same order as they occur in the List. The iteration
starts at the specified location.location - the index at which to start the iteration.List.IndexOutOfBoundsException - if location < 0 || location > size()ListIteratorE remove(int location)
List.location - the index of the object to remove.UnsupportedOperationException - if removing from this List is not supported.IndexOutOfBoundsException - if location < 0 || >= size()boolean remove(Object object)
List.remove in interface Collection<E>object - the object to remove.List was modified by this operation, false
otherwise.UnsupportedOperationException - if removing from this List is not supported.boolean removeAll(Collection<?> collection)
List of each object in the specified
collection.removeAll in interface Collection<E>collection - the collection of objects to remove.true if this List is modified, false otherwise.UnsupportedOperationException - if removing from this List is not supported.boolean retainAll(Collection<?> collection)
List that are not contained in the
specified collection.retainAll in interface Collection<E>collection - the collection of objects to retain.true if this List is modified, false otherwise.UnsupportedOperationException - if removing from this List is not supported.E set(int location, E object)
List with the
specified object. This operation does not change the size of the List.location - the index at which to put the specified object.object - the object to insert.UnsupportedOperationException - if replacing elements in this List is not supported.ClassCastException - if the class of an object is inappropriate for this
List.IllegalArgumentException - if an object cannot be added to this List.IndexOutOfBoundsException - if location < 0 || >= size()int size()
List.size in interface Collection<E>List.List<E> subList(int start, int end)
List of the specified portion of this List from the given start
index to the end index minus one. The returned List is backed by this
List so changes to it are reflected by the other.start - the index at which to start the sublist.end - the index one past the end of the sublist.List.IndexOutOfBoundsException - if start < 0, start > end or end >
size()Object[] toArray()
List.toArray in interface Collection<E>List.<T> T[] toArray(T[] array)
List. If the
specified array is large enough to hold the elements, the specified array
is used, otherwise an array of the same type is created. If the specified
array is used and is larger than this List, the array element following
the collection elements is set to null.toArray in interface Collection<E>array - the array.List.ArrayStoreException - if the type of an element in this List cannot be stored
in the type of the specified array.