AbstractList

public abstract class AbstractList extends AbstractCollection<E>
implements List<E>
Known Direct Subclasses
Known Indirect Subclasses

This class provides a skeletal implementation of the List interface to minimize the effort required to implement this interface backed by a "random access" data store (such as an array). For sequential access data (such as a linked list), AbstractSequentialList should be used in preference to this class.

To implement an unmodifiable list, the programmer needs only to extend this class and provide implementations for the get(int) and size() methods.

To implement a modifiable list, the programmer must additionally override the set(int, E) method (which otherwise throws an UnsupportedOperationException). If the list is variable-size the programmer must additionally override the add(int, E) and remove(int) methods.

The programmer should generally provide a void (no argument) and collection constructor, as per the recommendation in the Collection interface specification.

Unlike the other abstract collection implementations, the programmer does not have to provide an iterator implementation; the iterator and list iterator are implemented by this class, on top of the "random access" methods: get(int), set(int, E), add(int, E) and remove(int).

The documentation for each non-abstract method in this class describes its implementation in detail. Each of these methods may be overridden if the collection being implemented admits a more efficient implementation.

This class is a member of the Java Collections Framework.

Field Summary

protected int modCount The number of times this list has been structurally modified.

Protected Constructor Summary

AbstractList()
Sole constructor.

Public Method Summary

void
add(int index, E element)
Inserts the specified element at the specified position in this list (optional operation).

This implementation always throws an UnsupportedOperationException.

boolean
add(E e)
Appends the specified element to the end of this list (optional operation).
boolean
addAll(int index, Collection<? extends E> c)
Inserts all of the elements in the specified collection into this list at the specified position (optional operation).

This implementation gets an iterator over the specified collection and iterates over it, inserting the elements obtained from the iterator into this list at the appropriate position, one at a time, using add(int, E).

void
clear()
Removes all of the elements from this list (optional operation).
boolean
equals(Object o)
Compares the specified object with this list for equality.
abstract E
get(int index)
Returns the element at the specified position in this list.
int
hashCode()
Returns the hash code value for this list.
int
indexOf(Object o)
Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

This implementation first gets a list iterator (with listIterator()).

Iterator<E>
iterator()
Returns an iterator over the elements in this list in proper sequence.
int
lastIndexOf(Object o)
Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.

This implementation first gets a list iterator that points to the end of the list (with listIterator(size())).

ListIterator<E>
listIterator(int index)
Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.

This implementation returns a straightforward implementation of the ListIterator interface that extends the implementation of the Iterator interface returned by the iterator() method.

ListIterator<E>
listIterator()
Returns a list iterator over the elements in this list (in proper sequence).

This implementation returns listIterator(0).

E
remove(int index)
Removes the element at the specified position in this list (optional operation).

This implementation always throws an UnsupportedOperationException.

E
set(int index, E element)
Replaces the element at the specified position in this list with the specified element (optional operation).

This implementation always throws an UnsupportedOperationException.

List<E>
subList(int fromIndex, int toIndex)
Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.

This implementation returns a list that subclasses AbstractList.

Protected Method Summary

void
removeRange(int fromIndex, int toIndex)
Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive.

Inherited Method Summary