Top Description Inners Fields Constructors Methods
java.util

public abstract Class AbstractList<E>

extends AbstractCollection<E>
implements List<E>
Class Inheritance
All Implemented Interfaces
java.util.List, java.util.SequencedCollection, java.util.Collection, java.lang.Iterable
Known Direct Subclasses
java.util.AbstractList.SubList, java.util.AbstractSequentialList, java.util.ArrayList, java.util.ArrayList.SubList, java.util.Arrays.ArrayList, java.util.Collections.EmptyList, java.util.Collections.SingletonList, java.util.Collections.CopiesList, java.util.Vector, java.lang.invoke.AbstractConstantGroup.AsList, jdk.internal.classfile.impl.ClassPrinterImpl.ListNodeImpl
Type Parameters
<E>
the type of elements in this list
Imports
java.util.function.Consumer

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.

Authors
Josh Bloch, Neal Gafter
Since
1.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class
pack-priv static class
AbstractList.RandomAccessSpliterator<E>

An index-based split-by-two, lazily initialized Spliterator covering a List that access elements via List#get.

private static class
private static class

Field Summary

Modifier and TypeField and Description
protected transient int
modCount

The number of times this list has been structurally modified.

Constructor Summary

AccessConstructor and Description
protected
AbstractList()

Sole constructor.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true (as specified by Collection#add)
add
(E
element to be appended to this list
e
)

Overrides java.util.AbstractCollection.add.

Implements java.util.List.add, java.util.Collection.add.

Appends the specified element to the end of this list (optional operation).

public void
add(int
index at which the specified element is to be inserted
index
,
E
element to be inserted
element
)

Implements java.util.List.add.

Inserts the specified element at the specified position in this list (optional operation).

public boolean
addAll(int
index at which to insert the first element from the specified collection
index
,
Collection<? extends E>
collection containing elements to be added to this list
c
)

Implements java.util.List.addAll.

Inserts all of the elements in the specified collection into this list at the specified position (optional operation).

public void
clear()

Overrides java.util.AbstractCollection.clear.

Implements java.util.List.clear, java.util.Collection.clear.

Removes all of the elements from this list (optional operation).

public boolean

Returns:

true if the specified object is equal to this list
equals
(Object
the object to be compared for equality with this list
o
)

Overrides java.lang.Object.equals.

Implements java.util.List.equals, java.util.Collection.equals.

Compares the specified object with this list for equality.

public abstract E
get(int
index of the element to return
index
)

Redeclares java.util.List.get.

Returns the element at the specified position in this list.

public int

Returns:

the hash code value for this list
hashCode
()

Overrides java.lang.Object.hashCode.

Implements java.util.List.hashCode, java.util.Collection.hashCode.

Returns the hash code value for this list.

public int
indexOf(Object
element to search for
o
)

Implements java.util.List.indexOf.

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

public Iterator<E>

Returns:

an iterator over the elements in this list in proper sequence
iterator
()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.List.iterator, java.util.Collection.iterator.

Returns an iterator over the elements in this list in proper sequence.

public int
lastIndexOf(Object
element to search for
o
)

Implements java.util.List.lastIndexOf.

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.

public ListIterator<E>
listIterator()

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence).

public ListIterator<E>
listIterator(final int
index of the first element to be returned from the list iterator (by a call to next)
index
)

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.

private String
outOfBoundsMsg(int index)

private void
rangeCheckForAdd(int index)

public E
remove(int
the index of the element to be removed
index
)

Implements java.util.List.remove.

Removes the element at the specified position in this list (optional operation).

protected void
removeRange(int
index of first element to be removed
fromIndex
,
int
index after last element to be removed
toIndex
)

Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive.

public E
set(int
index of the element to replace
index
,
E
element to be stored at the specified position
element
)

Implements java.util.List.set.

Replaces the element at the specified position in this list with the specified element (optional operation).

public List<E>
subList(int
low endpoint (inclusive) of the subList
fromIndex
,
int
high endpoint (exclusive) of the subList
toIndex
)

Implements java.util.List.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.

pack-priv static void
subListRangeCheck(int fromIndex, int toIndex, int size)

Inherited from java.util.AbstractCollection:
addAllcontainscontainsAllisEmptyremoveremoveAllretainAllsizetoArraytoArraytoString