加载中...
The Wayback Machine - https://sup1a9wrlpyh5li9ro.vcoronado.top/web/20090218195213/http://developer.android.com:80/reference/java/util/AbstractList.html
public abstract class

AbstractList

extends AbstractCollection<E>
implements List<E>
java.lang.Object
   ↳ java.util.AbstractCollection<E>
     ↳ java.util.AbstractList<E>
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

AbstractList is an abstract implementation of the List interface, optimized for a backing store which supports random access. This implementation does not support adding or replacing. A subclass must implement the abstract methods get() and size().

Summary

Fields
protected int modCount
Protected Constructors
AbstractList()
Constructs a new instance of this AbstractList.
Public Methods
void add(int location, E object)
Inserts the specified object into this List at the specified location.
boolean add(E object)
Adds the specified object at 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 equals(Object object)
Compares the specified object to this List and answer if they are equal.
abstract E get(int location)
Returns the element at the specified location in this List.
int hashCode()
Returns an integer hash code for the receiver.
int indexOf(Object object)
Searches this List for the specified object and returns the index of the first occurrence.
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 ListIterator on the elements of this List.
ListIterator<E> listIterator(int location)
Returns a ListIterator on the elements of this List.
E remove(int location)
Removes the object at the specified location from this List.
E set(int location, E object)
Replaces the element at the specified location in this List with the specified object.
List<E> subList(int start, int end)
Returns a part of consecutive elements of this list as a view.
Protected Methods
void removeRange(int start, int end)
Removes the objects in the specified range from the start to the, but not including, end index.
[Expand]
Inherited Methods
From class java.util.AbstractCollection
From class java.lang.Object
From interface java.lang.Iterable
From interface java.util.Collection
From interface java.util.List

Fields

protected int modCount

Protected Constructors

protected AbstractList ()

Constructs a new instance of this AbstractList.

Public Methods

public void add (int location, E object)

Inserts the specified object into this List at the specified location. The object is inserted before any previous element at the specified location. If the location is equal to the size of this List, the object is added at the end.

Parameters
location the index at which to insert
object the object to add
Throws
UnsupportedOperationException when adding to this List is not supported
ClassCastException when the class of the object is inappropriate for this List
IllegalArgumentException when the object cannot be added to this List
IndexOutOfBoundsException when location < 0 || >= size()

public boolean add (E object)

Adds the specified object at the end of this List.

Parameters
object the object to add
Returns
  • true
Throws
UnsupportedOperationException when adding to this List is not supported
ClassCastException when the class of the object is inappropriate for this List
IllegalArgumentException when the object cannot be added to this List

public 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 iterator.

Parameters
location the index at which to insert
collection the Collection of objects
Returns
  • true if this List is modified, false otherwise
Throws
UnsupportedOperationException when adding to this List is not supported
ClassCastException when the class of an object is inappropriate for this List
IllegalArgumentException when an object cannot be added to this List
IndexOutOfBoundsException when location < 0 || >= size()

public void clear ()

Removes all elements from this List, leaving it empty.

Throws
UnsupportedOperationException when removing from this List is not supported
See Also

public boolean equals (Object object)

Compares the specified object to this List and answer if they are equal. The object must be a List which contains the same objects in the same order.

Parameters
object the object to compare with this object
Returns
  • true if the specified object is equal to this List, false otherwise
See Also

public abstract E get (int location)

Returns the element at the specified location in this List.

Parameters
location the index of the element to return
Returns
  • the element at the specified index
Throws
IndexOutOfBoundsException when location < 0 || >= size()

public int hashCode ()

Returns an integer hash code for the receiver. Objects which are equal answer the same value for this method.

Returns
  • the receiver's hash
See Also

public int indexOf (Object object)

Searches this List for the specified object and returns the index of the first occurrence.

Parameters
object the object to search for
Returns
  • the index of the first occurrence of the object

public Iterator<E> iterator ()

Returns an Iterator on the elements of this List. The elements are iterated in the same order that they occur in the List.

Returns
  • an Iterator on the elements of this List
See Also

public int lastIndexOf (Object object)

Searches this List for the specified object and returns the index of the last occurrence.

Parameters
object the object to search for
Returns
  • the index of the last occurrence of the object

public ListIterator<E> listIterator ()

Returns a ListIterator on the elements of this List. The elements are iterated in the same order that they occur in the List.

Returns
  • a ListIterator on the elements of this List
See Also

public ListIterator<E> listIterator (int location)

Returns a ListIterator on the elements of this List. The elements are iterated in the same order that they occur in the List. The iteration starts at the specified location.

Parameters
location the index at which to start the iteration
Returns
  • a ListIterator on the elements of this List
Throws
IndexOutOfBoundsException when location < 0 || >= size()
See Also

public E remove (int location)

Removes the object at the specified location from this List.

Parameters
location the index of the object to remove
Returns
  • the removed object
Throws
UnsupportedOperationException when removing from this List is not supported
IndexOutOfBoundsException when location < 0 || >= size()

public E set (int location, E object)

Replaces the element at the specified location in this List with the specified object.

Parameters
location the index at which to put the specified object
object the object to add
Returns
  • the previous element at the index
Throws
UnsupportedOperationException when replacing elements in this List is not supported
ClassCastException when the class of an object is inappropriate for this List
IllegalArgumentException when an object cannot be added to this List
IndexOutOfBoundsException when location < 0 || >= size()

public List<E> subList (int start, int end)

Returns a part of consecutive elements of this list as a view. From start (inclusive), to end(exclusive). The returned view will be of zero length if start equals end. Any change occurs in the returned subList will be reflected to the original list, and vice-versa. All the supported optional operations by the original list will also be supported by this subList. This method can be used as a handy method to do some operations on a sub range of the original list. For example: list.subList(from, to).clear(); If the original list is modified other than through the returned subList, the behavior of the returned subList becomes undefined. The returned subList is a subclass of AbstractList. The subclass stores offset, size of itself, and modCount of the original list. If the original list implements RandomAccess interface, the returned subList also implements RandomAccess interface. The subList's set(int, Object), get(int), add(int, Object), remove(int), addAll(int, Collection) and removeRange(int, int) methods first check the bounds, adjust offsets and then call the corresponding methods of the original AbstractList. addAll(Collection c) method of the returned subList calls the original addAll(offset + size, c). The listIterator(int) method of the subList wraps the original list iterator. The iterator() method of the subList invokes the original listIterator() method, and the size() method merely returns the size of the subList. All methods will throw a ConcurrentModificationException if the modCount of the original list is not equal to the expected value.

Parameters
start start index of the subList, include start
end end index of the subList, exclude end
Returns
  • a subList view of this list start from start (inclusive), end with end (exclusive)
Throws
IndexOutOfBoundsException when (start < 0 || end > size())
IllegalArgumentException when (start > end)

Protected Methods

protected void removeRange (int start, int end)

Removes the objects in the specified range from the start to the, but not including, end index.

Parameters
start the index at which to start removing
end the index one past the end of the range to remove
Throws
UnsupportedOperationException when removing from this List is not supported
IndexOutOfBoundsException when start < 0