public interface List<E>
ExtendsCollection<E>, Iterable<E>
Known subtypesAbstractList, AbstractSequentialList, ArrayList, LinkedList, Stack, Vector
A
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.Methods
public abstract void add(int location, E object) | Inserts the specified object into this List at the specified location. |
public abstract boolean add(E object) | Adds the specified object at the end of this List. |
public abstract boolean addAll(int location, Collection<? extends E> collection) | Inserts the objects in the specified collection at the specified location in this List. |
public abstract boolean addAll(Collection<? extends E> collection) | Adds the objects in the specified collection to the end of this List. |
public abstract void clear() | Removes all elements from this List, leaving it empty. |
public abstract boolean contains(Object object) | Tests whether this List contains the specified object. |
public abstract boolean containsAll(Collection<?> collection) | Tests whether this List contains all objects contained in the specified collection. |
public abstract 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. |
public abstract E get(int location) | Returns the element at the specified location in this List. |
public abstract int hashCode() | Returns the hash code for this List. |
public abstract int indexOf(Object object) | Searches this List for the specified object and returns the index of the first occurrence. |
public abstract boolean isEmpty() | Returns whether this List contains no elements. |
public abstract Iterator<E> iterator() | Returns an iterator on the elements of this List. |
public abstract int lastIndexOf(Object object) | Searches this List for the specified object and returns the index of the last occurrence. |
public abstract ListIterator<E> listIterator() | Returns a List iterator on the elements of this List. |
public abstract ListIterator<E> listIterator(int location) | Returns a list iterator on the elements of this List. |
public abstract E remove(int location) | Removes the object at the specified location from this List. |
public abstract boolean remove(Object object) | Removes the first occurrence of the specified object from this List. |
public abstract boolean removeAll(Collection<?> collection) | Removes all occurrences in this List of each object in the specified collection. |
public abstract boolean retainAll(Collection<?> collection) | Removes all objects from this List that are not contained in the specified collection. |
public abstract E set(int location, E object) | Replaces the element at the specified location in this List with the specified object. |
public abstract int size() | Returns the number of elements in this List. |
public abstract 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. |
public abstract Object[] toArray() | Returns an array containing all elements contained in this List. |
public abstract <T> T[] toArray(T[] array) | Returns an array containing all elements contained in this List. |
public default void replaceAll(UnaryOperator<E> operator) | Replaces each element of this list with the result of applying the operator to that element. |
public default void sort(Comparator<? super E> c) | Sorts this list according to the order induced by the specified Comparator. |
Inherited methods
From Collection
Method details
add
public abstract void add(int location, E object)Inserts the specified object into this
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.Parameters
locationint- the index at which to insert.
objectE- the object to add.
Throws
UnsupportedOperationException- if adding to this
Listis 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 size()
add
public abstract boolean add(E object)Adds the specified object at the end of this
List.Parameters
objectE- the object to add.
Returns
always true.
Throws
UnsupportedOperationException- if adding to this
Listis not supported. ClassCastException- if the class of the object is inappropriate for this
List. IllegalArgumentException- if the object cannot be added to this
List.
addAll
public abstract boolean addAll(int location, Collection<? extends E> collection)Inserts the objects in the specified collection at the specified location
in this
List. The objects are added in the order they are returned from
the collection’s iterator.Parameters
locationint- the index at which to insert.
collectionCollection<? extends E>- the collection of objects to be inserted.
Returns
true if this
List has been modified through the insertion, false
otherwise (i.e. if the passed collection was empty).Throws
UnsupportedOperationException- if adding to this
Listis 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 size()
addAll
public abstract boolean addAll(Collection<? extends E> collection)Adds the objects in the specified collection to the end of this
List. The
objects are added in the order in which they are returned from the
collection’s iterator.Parameters
collectionCollection<? extends E>- the collection of objects.
Returns
true if this List is modified, false otherwise
(i.e. if the passed collection was empty).Throws
UnsupportedOperationException- if adding to this
Listis not supported. ClassCastException- if the class of an object is inappropriate for this
List. IllegalArgumentException- if an object cannot be added to this
List.
clear
public abstract void clear()Removes all elements from this
List, leaving it empty.Throws
UnsupportedOperationException- if removing from this
Listis not supported.
contains
public abstract boolean contains(Object object)Tests whether this
List contains the specified object.Parameters
objectObject- the object to search for.
Returns
true if object is an element of this List, false
otherwisecontainsAll
public abstract boolean containsAll(Collection<?> collection)Tests whether this
List contains all objects contained in the
specified collection.Parameters
collectionCollection<?>- the collection of objects
Returns
true if all objects in the specified collection are
elements of this List, false otherwise.equals
public abstract 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. For
Lists, this means that they contain the same elements in exactly the same
order.Parameters
objectObject- the object to compare with this object.
Returns
boolean
true if the object is the same as this object,
and false if it is different from this object.See also
get
public abstract E get(int location)Returns the element at the specified location in this
List.Parameters
locationint- the index of the element to return.
Returns
the element at the specified location.
Throws
IndexOutOfBoundsException- if
location = size()
hashCode
public abstract int hashCode()Returns the hash code for this
List. It is calculated by taking each
element’ hashcode and its position in the List into account.Returns
the hash code of the
List.indexOf
public abstract int indexOf(Object object)Searches this
List for the specified object and returns the index of the
first occurrence.Parameters
objectObject- the object to search for.
Returns
the index of the first occurrence of the object or -1 if the
object was not found.
isEmpty
public abstract boolean isEmpty()Returns whether this
List contains no elements.Returns
true if this List has no elements, false
otherwise.See also
iterator
public abstract Iterator<E> iterator()Returns an iterator on the elements of this
List. The elements are
iterated in the same order as they occur in the List.Returns
an iterator on the elements of this
List.See also
lastIndexOf
public abstract int lastIndexOf(Object object)Searches this
List for the specified object and returns the index of the
last occurrence.Parameters
objectObject- the object to search for.
Returns
the index of the last occurrence of the object, or -1 if the
object was not found.
listIterator
public abstract ListIterator<E> listIterator()Returns a
List iterator on the elements of this List. The elements are
iterated in the same order that they occur in the List.Returns
a
List iterator on the elements of this ListSee also
listIterator
public abstract ListIterator<E> listIterator(int location)Returns a list iterator on the elements of this
List. The elements are
iterated in the same order as they occur in the List. The iteration
starts at the specified location.Parameters
locationint- the index at which to start the iteration.
Returns
a list iterator on the elements of this
List.Throws
IndexOutOfBoundsException- if
location size()
See also
remove
public abstract E remove(int location)Removes the object at the specified location from this
List.Parameters
locationint- the index of the object to remove.
Returns
the removed object.
Throws
UnsupportedOperationException- if removing from this
Listis not supported. IndexOutOfBoundsException- if
location = size()
remove
public abstract boolean remove(Object object)Removes the first occurrence of the specified object from this
List.Parameters
objectObject- the object to remove.
Returns
true if this
List was modified by this operation, false
otherwise.Throws
UnsupportedOperationException- if removing from this
Listis not supported.
removeAll
public abstract boolean removeAll(Collection<?> collection)Removes all occurrences in this
List of each object in the specified
collection.Parameters
collectionCollection<?>- the collection of objects to remove.
Returns
true if this List is modified, false otherwise.Throws
UnsupportedOperationException- if removing from this
Listis not supported.
retainAll
public abstract boolean retainAll(Collection<?> collection)Removes all objects from this
List that are not contained in the
specified collection.Parameters
collectionCollection<?>- the collection of objects to retain.
Returns
true if this List is modified, false otherwise.Throws
UnsupportedOperationException- if removing from this
Listis not supported.
set
public abstract E set(int location, E object)Replaces the element at the specified location in this
List with the
specified object. This operation does not change the size of the List.Parameters
locationint- the index at which to put the specified object.
objectE- the object to insert.
Returns
the previous element at the index.
Throws
UnsupportedOperationException- if replacing elements in this
Listis 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 = size()
size
public abstract int size()Returns the number of elements in this
List.Returns
the number of elements in this
List.subList
public abstract 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. The returned List is backed by this
List so changes to it are reflected by the other.Parameters
startint- the index at which to start the sublist.
endint- the index one past the end of the sublist.
Returns
a list of a portion of this
List.Throws
IndexOutOfBoundsException- if
start endorend > size()
toArray
public abstract Object[] toArray()Returns an array containing all elements contained in this
List.Returns
an array of the elements from this
List.toArray
public abstract <T> T[] toArray(T[] array)Returns an array containing all elements contained in this
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.Parameters
arrayT[]- the array.
Returns
an array of the elements from this
List.Throws
ArrayStoreException- if the type of an element in this
Listcannot be stored in the type of the specified array.
replaceAll
public default void replaceAll(UnaryOperator<E> operator)Replaces each element of this list with the result of applying
the operator to that element. Stubbed in the CLDC11 subset;
the actual implementation comes from the platform’s JDK at
runtime.
sort
public default void sort(Comparator<? super E> c)Sorts this list according to the order induced by the specified
Comparator. Stubbed in the CLDC11 subset; the actual
implementation comes from the platform’s JDK at runtime.