public abstract class AbstractSequentialList<E> extends AbstractList<E>
这个类是在这个意义上AbstractList类相反,它实现了对列表的列表迭代器顶部的“随机访问”方法(get(int index),set(int index, E element),add(int index, E element)和remove(int index)),而不是周围的其他方法。
为了实现一个列表,程序员只需要扩展这个类,并提供listIterator和size方法的实现。 对于一个不可修改的列表,程序员只需要实现列表迭代器的hasNext,next,hasPrevious,previous和index方法。
对于可修改的列表,程序员应该另外实现list iterator的set方法。 对于可变大小的列表,程序员应该另外实现list iterator的remove和add方法。
根据Collection接口规范中的建议,程序员通常应该提供一个void(无参数)和集合构造函数。
这个类是Java Collections Framework的成员。
Collection , List , AbstractList , AbstractCollection
modCount| Modifier | Constructor and Description |
|---|---|
protected |
AbstractSequentialList()
唯一的构造函数。
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(int index, E element)
将指定的元素插入此列表中的指定位置(可选操作)。
|
boolean |
addAll(int index, Collection<? extends E> c)
将指定集合中的所有元素插入到此列表中的指定位置(可选操作)。
|
E |
get(int index)
返回此列表中指定位置的元素。
|
Iterator<E> |
iterator()
返回此列表中的元素的迭代器(按适当的顺序)。
|
abstract ListIterator<E> |
listIterator(int index)
返回列表中的列表迭代器(按适当的顺序)。
|
E |
remove(int index)
删除该列表中指定位置的元素(可选操作)。
|
E |
set(int index, E element)
用指定的元素(可选操作)替换此列表中指定位置的元素。
|
add, clear, equals, hashCode, indexOf, lastIndexOf, listIterator, removeRange, subListaddAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, size, toArray, toArray, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitaddAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, size, sort, spliterator, toArray, toArrayparallelStream, removeIf, streampublic E get(int index)
此实现首先获取指向索引元素的列表迭代器(具有listIterator(index) )。 然后,它使用ListIterator.next获取元素并返回。
get在界面
List<E>
get在类别
AbstractList<E>
index - 要返回的元素的索引
IndexOutOfBoundsException - 如果索引超出范围(
index < 0 || index >= size() )
public E set(int index, E element)
此实现首先获取指向索引元素的列表迭代器(具有listIterator(index) )。 然后,用ListIterator.next获得当前元素,并与ListIterator.set替换它。
注意,此实现将抛出UnsupportedOperationException如果列表迭代器没有实现set操作。
set在界面
List<E>
set在类别
AbstractList<E>
index - 要替换的元素的索引
element - 要存储在指定位置的元素
UnsupportedOperationException -如果
set操作不受此列表支持
ClassCastException - 如果指定元素的类阻止将其添加到此列表中
NullPointerException - 如果指定的元素为空,并且该列表不允许空元素
IllegalArgumentException - 如果指定元素的某些属性阻止将其添加到此列表中
IndexOutOfBoundsException - 如果索引超出范围(
index < 0 || index >= size() )
public void add(int index,
E element)
此实现首先获取指向索引元素的列表迭代器(具有listIterator(index) )。 然后,它插入与ListIterator.add指定的元素。
注意,此实现将抛出UnsupportedOperationException如果列表迭代器没有实现add操作。
add在界面
List<E>
add在类别
AbstractList<E>
index - 要插入指定元素的索引
element - 要插入的元素
UnsupportedOperationException -如果
add操作不受此列表支持
ClassCastException - 如果指定元素的类阻止将其添加到此列表中
NullPointerException - 如果指定的元素为空,并且该列表不允许空元素
IllegalArgumentException - 如果指定元素的某些属性阻止将其添加到此列表
IndexOutOfBoundsException - 如果索引超出范围(
index < 0 || index > size() )
public E remove(int index)
此实现首先获取指向索引元素的列表迭代器(使用listIterator(index) )。 然后,它用ListIterator.remove删除元素。
注意,此实现将抛出UnsupportedOperationException如果列表迭代器没有实现remove操作。
remove在界面
List<E>
remove在类别
AbstractList<E>
index - 要删除的元素的索引
UnsupportedOperationException -如果
remove操作不受此列表支持
IndexOutOfBoundsException - 如果索引超出范围(
index < 0 || index >= size() )
public boolean addAll(int index,
Collection<? extends E> c)
该实现在指定的集合上获得一个迭代器,并通过该列表指向索引元素(具有listIterator(index) )的列表迭代器。 然后,它迭代指定的集合,将从迭代器获取的元素插入到此列表中,一次一个,使用ListIterator.add后跟ListIterator.next (跳过添加的元素)。
注意,此实现将抛出UnsupportedOperationException如果由listIterator方法返回的列表迭代器没有实现add操作。
addAll在界面
List<E>
addAll在类别
AbstractList<E>
index - 从中指定集合插入第一个元素的索引
c - 包含要添加到此列表的元素的集合
UnsupportedOperationException -如果
addAll操作不受此列表支持
ClassCastException - 如果指定集合的元素的类阻止将其添加到此列表
NullPointerException - 如果指定的集合包含一个或多个空元素,并且此列表不允许空元素,或者如果指定的集合为空
IllegalArgumentException - 如果指定集合的元素的某些属性阻止其添加到此列表中
IndexOutOfBoundsException - 如果索引超出范围(
index < 0 || index > size() )
public abstract ListIterator<E> listIterator(int index)
listIterator在接口
List<E>
listIterator在类别
AbstractList<E>
index - 要从列表迭代器返回的第一个元素的索引(通过调用
next方法)
IndexOutOfBoundsException - 如果索引超出范围(
index < 0 || index > size() )
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.