AbstractSequentialList
构造函数
protected AbstractSequentialList() {
}
成员变量
方法
1、public E get(int index)
public E get(int index) {
try {
return listIterator(index).next();
} catch (NoSuchElementException exc) {
throw new IndexOutOfBoundsException("Index: "+index);
}
}
调用listIterator返回指定下标的值
2、public E set(int index, E element)
public E set(int index, E element) {
try {
ListIterator<E> e = listIterator(index);
E oldVal = e.next();
e.set(element);
return oldVal;
} catch (NoSuchElementException exc) {
throw new IndexOutOfBoundsException("Index: "+index);
}
}
调用listIterator返回指定下标index的值,并替换成指定值element
3、public void add(int index, E element)
public void add(int index, E element) {
try {
listIterator(index).add(element);
} catch (NoSuchElementException exc) {
throw new IndexOutOfBoundsException("Index: "+index);
}
}
调用listIterator在指定下标处加入元素
4、public E remove(int index)
public E remove(int index) {
try {
ListIterator<E> e = listIterator(index);
E outCast = e.next();
e.remove();
return outCast;
} catch (NoSuchElementException exc) {
throw new IndexOutOfBoundsException("Index: "+index);
}
}
调用listIterator越过指定下标元素后删除
5、public boolean addAll(int index, Collection<? extends E> c)
public boolean addAll(int index, Collection<? extends E> c) {
try {
boolean modified = false;
ListIterator<E> e1 = listIterator(index);
Iterator<? extends E> e2 = c.iterator();
while (e2.hasNext()) {
e1.add(e2.next());
modified = true;
}
return modified;
} catch (NoSuchElementException exc) {
throw new IndexOutOfBoundsException("Index: "+index);
}
}
调用自身迭代器和c迭代器,不断添加元素
6、public Iterator iterator()
public Iterator<E> iterator() {
return listIterator();
}
返回一个listIterator
7、public abstract ListIterator listIterator(int index)
public abstract ListIterator<E> listIterator(int index);