java.lang.Object | +--java.util.Collection | +--java.util.ListAll Implemented Interfaces:
CollectionSetArrayListLinkedListVectorArrays#asList(Object[])Collections#nCopies(int, Object)Collections#EMPTY_LISTAbstractListAbstractSequentialList void | add(int index, java.lang.Object o)Insert an element into the list at a given position (optional operation). |
boolean | add(java.lang.Object o)Add an element to the end of the list (optional operation). |
boolean | addAll(int index, java.util.Collection c)Insert the contents of a collection into the list at a given position (optional operation). |
boolean | addAll(java.util.Collection c)Add the contents of a collection to the end of the list (optional operation). |
void | clear()Clear the list, such that a subsequent call to isEmpty() would return true (optional operation). |
boolean | contains(java.lang.Object o)Test whether this list contains a given object as one of its elements. |
boolean | containsAll(java.util.Collection c)Test whether this list contains every element in a given collection. |
boolean | equals(java.lang.Object o)Test whether this list is equal to another object. |
java.lang.Object | get(int index)Get the element at a given index in this list. |
int | hashCode()Obtains a hash code for this list. |
int | indexOf(java.lang.Object o)Obtain the first index at which a given object is to be found in this list. |
boolean | isEmpty()Test whether this list is empty, that is, if size() == 0. |
java.util.Iterator | iterator()Obtain an Iterator over this list, whose sequence is the list order. |
int | lastIndexOf(java.lang.Object o)Obtain the last index at which a given object is to be found in this list. |
java.util.ListIterator | listIterator()Obtain a ListIterator over this list, starting at the beginning. |
java.util.ListIterator | listIterator(int index)Obtain a ListIterator over this list, starting at a given position. |
java.lang.Object | remove(int index)Remove the element at a given position in this list (optional operation). |
boolean | remove(java.lang.Object o)Remove the first occurence of an object from this list (optional operation). |
boolean | removeAll(java.util.Collection c)Remove all elements of a given collection from this list (optional operation). |
boolean | retainAll(java.util.Collection c)Remove all elements of this list that are not contained in a given collection (optional operation). |
java.lang.Object | set(int index, java.lang.Object o)Replace an element of this list with another object (optional operation). |
int | size()Get the number of elements in this list. |
java.util.List | subList(int fromIndex, int toIndex)Obtain a List view of a subsection of this list, from fromIndex (inclusive) to toIndex (exclusive). |
java.lang.Object[] | toArray()Copy the current contents of this list into an array. |
java.lang.Object[] | toArray(java.lang.Object[] a)Copy the current contents of this list into an array. |
public void add(int index, java.lang.Object o)index - the location to insert the itemo - the object to insertUnsupportedOperationException - if this list does not support the
add operationIndexOutOfBoundsException - if index < 0 || index > size()ClassCastException - if o cannot be added to this list due to its
typeIllegalArgumentException - if o cannot be added to this list for
some other reasonpublic boolean add(java.lang.Object o)o - the object to addUnsupportedOperationException - if this list does not support the
add operationClassCastException - if o cannot be added to this list due to its
typeIllegalArgumentException - if o cannot be added to this list for
some other reasonpublic boolean addAll(int index, java.util.Collection c)index - the location to insert the collectionc - the collection to insertUnsupportedOperationException - if this list does not support the
addAll operationIndexOutOfBoundsException - if index < 0 || index > size()ClassCastException - if some element of c cannot be added to this
list due to its typeIllegalArgumentException - if some element of c cannot be added
to this list for some other reasonNullPointerException - if the specified collection is nullpublic boolean addAll(java.util.Collection c)c - the collection to addUnsupportedOperationException - if this list does not support the
addAll operationClassCastException - if some element of c cannot be added to this
list due to its typeIllegalArgumentException - if some element of c cannot be added
to this list for some other reasonNullPointerException - if the specified collection is nullpublic void clear()UnsupportedOperationException - if this list does not support the
clear operationpublic boolean contains(java.lang.Object o)o == null ? e == null : o.equals(e).
o - the element to look forpublic boolean containsAll(java.util.Collection c)c - the collection to test forNullPointerException - if the collection is nullpublic boolean equals(java.lang.Object o)l1.size() == l2.size(), and for every integer n between 0
and l1.size() - 1 inclusive, l1.get(n) == null ?
l2.get(n) == null : l1.get(n).equals(l2.get(n)).
o - the object to test for equality with this listpublic Object get(int index)index - the index of the element to be returnedIndexOutOfBoundsException - if index < 0 || index >= size()public int hashCode()hashCode = 1;
Iterator i = list.iterator();
while (i.hasNext())
{
Object obj = i.next();
hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
}
This ensures that the general contract of Object.hashCode() is adhered to.
public int indexOf(java.lang.Object o)o - the object to search foro == null ? get(n) == null :
o.equals(get(n)), or -1 if there is no such indexpublic boolean isEmpty()public Iterator iterator()public int lastIndexOf(java.lang.Object o)o - o == null ? get(n) == null
: o.equals(get(n)), or -1 if there is no such indexpublic ListIterator listIterator()public ListIterator listIterator(int index)index - the position, between 0 and size() inclusive, to begin the
iteration fromIndexOutOfBoundsException - if index < 0 || index > size()public Object remove(int index)index - the position within the list of the object to removeUnsupportedOperationException - if this list does not support the
remove operationIndexOutOfBoundsException - if index < 0 || index >= size()public boolean remove(java.lang.Object o)o == null ? e == null : o.equals(e).
o - the object to removeUnsupportedOperationException - if this list does not support the
remove operationpublic boolean removeAll(java.util.Collection c)c - the collection to filter outUnsupportedOperationException - if this list does not support the
removeAll operationNullPointerException - if the collection is nullpublic boolean retainAll(java.util.Collection c)c - the collection to retainUnsupportedOperationException - if this list does not support the
retainAll operationNullPointerException - if the collection is nullpublic Object set(int index, java.lang.Object o)index - the position within this list of the element to be replacedo - the object to replace it withUnsupportedOperationException - if this list does not support the
set operationIndexOutOfBoundsException - if index < 0 || index >= size()ClassCastException - if o cannot be added to this list due to its
typeIllegalArgumentException - if o cannot be added to this list for
some other reasonpublic int size()public List subList(int fromIndex, int toIndex)fromIndex - the index that the returned list should start from
(inclusive)toIndex - the index that the returned list should go to (exclusive)IndexOutOfBoundsException - if fromIndex < 0
|| toIndex > size() || fromIndex > toIndexIllegalArgumentException - if fromIndex > toIndex (according to
AbstractList).public Object[] toArray()public Object[] toArray(java.lang.Object[] a)a - the array to copy this list intoArrayStoreException - if the type of any element of the
collection is not a subtype of the element type of aNullPointerException - if the specified array is null
List places additional requirements on
iterator,add,remove,equals, andhashCode, in addition to requiring more methods. List indexing is 0-based (like arrays), although some implementations may require time proportional to the index to obtain an arbitrary element. The List interface is incompatible with Set; you cannot implement both simultaneously.Lists also provide a
ListIteratorwhich allows bidirectional traversal and other features atop regular iterators. Lists can be searched for arbitrary elements, and allow easy insertion and removal of multiple elements in one method call.Note: While lists may contain themselves as elements, this leads to undefined (usually infinite recursive) behavior for some methods like hashCode or equals.