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方法。
对于一个可修改的列表程序员应当实现列表迭代器的set方法。一个可变大小的列表,程序员应当实现列表迭代器的remove和add方法。
程序员通常提供一个空(无参数)和收集的构造函数,按推荐的Collection接口规范。
这个班的一员 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, streamprotected AbstractSequentialList()
public 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取代它。
注意,这个实现会如果列表迭代器没有实现set操作抛出UnsupportedOperationException。
set 接口
List<E>
set 方法重写,继承类
AbstractList<E>
index索引的元素代替
element元素被存储在指定的位置
UnsupportedOperationException -如果
set操作不该列表支持
ClassCastException -如果指定元素类型阻止其加入列表
NullPointerException -如果指定元素为null,这个列表不允许null元素
IllegalArgumentException -如果指定元素的一些特性阻止其加入列表
IndexOutOfBoundsException如果索引超出范围(
index < 0 || index >= size())
public void add(int index,
E element)
实现首先获取列表迭代器指向的元素的索引(与listIterator(index))。然后,它插入指定元素的ListIterator.add。
注意,这个实现会如果列表迭代器没有实现add操作抛出UnsupportedOperationException。
add 接口
List<E>
add 方法重写,继承类
AbstractList<E>
index指数在指定的元素被插入
element元素被插入
UnsupportedOperationException -如果
add操作不该列表支持
ClassCastException -如果指定元素类型阻止其加入列表
NullPointerException -如果指定元素为null,这个列表不允许null元素
IllegalArgumentException -如果指定元素的一些特性阻止其加入列表
IndexOutOfBoundsException如果索引超出范围(
index < 0 || index > size())
public E remove(int index)
实现首先获取列表迭代器指向的元素的索引(与listIterator(index))。然后,它消除了元ListIterator.remove。
注意,这个实现会如果列表迭代器没有实现remove操作抛出UnsupportedOperationException。
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(跳过添加元素)。
注意,这个实现会如果由listIterator方法返回的列表迭代器没有实现add操作抛出UnsupportedOperationException。
addAll 接口
List<E>
addAll 方法重写,继承类
AbstractList<E>
index指数,从指定集合的第一个元素的插入
c收集含有的元素被添加到列表
UnsupportedOperationException -如果
addAll操作不该列表支持
ClassCastException -如果指定集合的元素的类,防止它被添加到列表
NullPointerException -如果指定集合包含一个或多个null元素而列表不允许null元素,或者指定集合为空
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.