java.util.AbstractList

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)

这个类提供了List接口的框架实现,来降低实现支持随机访问数据存储接口的复杂程度(例如ArrayList)。 对于顺序存取的数据(如LinkedList),应优先使用 AbstractSequentialList

只需要扩展这个类并提供get(int)size()方法的实现,来实现一个不可修改的列表

再覆盖set(int, E)方法(否则会抛出一个UnsupportedOperationException ),来实现可修改的列表

覆盖add(int, E)remove(int)方法,实现可变大小的列表

根据集合接口规范中的建议,需要提供一个无参构造函数。

除了用于随机访问的四个方法:get(int)set(int, E)add(int, E) and remove(int)需要实现,子类可以不用再去实现iterator 和 list iterator这两个迭代器。

其他非抽象类用法和功能在文档里都有详细描述,如果有需要,可以重写这些方法。

主要方法:abstract E get(int index),返回指定位置的元素。主要用于List中

原文地址:https://www.cnblogs.com/xiaotianblog/p/12613152.html