- public interface List<E> extends Collection<E> {
- int size();
- boolean isEmpty();
- boolean contains(Object o);
- Iterator<E> iterator();
- Object[] toArray();
- <T> T[] toArray(T[] a);
- boolean add(E e);
- boolean remove(Object o);
- boolean containsAll(Collection<?> c);
- boolean addAll(Collection<? extends E> c);
- boolean addAll( int index, Collection<? extends E> c);
- boolean removeAll(Collection<?> c);
- boolean retainAll(Collection<?> c);
- void clear();
- boolean equals(Object o);
- int hashCode();
- E get( int index);
- E set( int index, E element);
- void add( int index, E element);
- E remove( int index);
- int indexOf(Object o);
- int lastIndexOf(Object o);
- ListIterator<E> listIterator();
- ListIterator<E> listIterator( int index);
- List<E> subList( int fromIndex, int toIndex);
- }
再看下 ArrayList 的定义,
public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, java.io.Serializable
可以看出 ArrayList 继承 AbstractList(这是一个抽象类, 对一些基础的 list 操作进行封装), 实现 List,RandomAccess,Cloneable,Serializable 几个接口, RandomAccess 是一个标记接口, 用来表明其支持快速随机访问.
2. 底层存储
顾名思义哈, ArrayList 就是用数组实现的 List 容器, 既然是用数组实现, 当然底层用数组来保存数据啦...
来源: http://blog.51cto.com/13932491/2173426