Java源码——List

public interface List extends Collection 接口

List 方法区:

int size();

1
2
int ();

boolean isEmpty();

1
2
//判断数组是否为空
boolean isEmpty();

boolean contains(Object o);

1
2
//判断容器中是否存在这个元素
boolean contains(Object o);

Iterator iterator();

1
2
//返回List的迭代
Iterator<E> iterator();

Object[] toArray();

1
2
//List转化为Object数组
Object[] toArray();

T[] toArray(T[] a);

1
2
//将List中的元素转换成T[]数组返回
<T> T[] toArray(T[] a);

boolean add(E e);

1
2
//添加元素
boolean add(E e);

boolean remove(Object o);

1
2
//移除元素
boolean remove(Object o);

boolean containsAll(Collection<?> c);

1
2
//判断是否包含C中的所有元素
boolean containsAll(Collection<?> c);

boolean addAll(int index, Collection<? extends E> c);

1
2
//在List数组index位置中添加C中的所有元素
boolean addAll(int index, Collection<? extends E> c);

boolean removeAll(Collection<?> c);

1
2
//移除List中所有在C中出现的元素
boolean removeAll(Collection<?> c);

boolean retainAll(Collection<?> c);

1
2
//移除List中所有没有在C中出现的元素
boolean retainAll(Collection<?> c);

void clear();

1
2
//清空数组
void clear();

boolean equals(Object o);

1
2
//判断List是否和Object相等
boolean equals(Object o);

int hashCode();

1
2
//放回List的hashCode
int hashCode();

E get(int index);

1
2
//获取List中下标为index的元素
E get(int index);

E set(int index, E element);

1
2
//将元素element插入List的index位置中
E set(int index, E element);

E remove(int index);

1
2
//移除List中index位置的元素
E remove(int index);

int indexOf(Object o);

1
2
//获取元素o在List中第一次出现的位置
int indexOf(Object o);

int lastIndexOf(Object o);

1
2
//获取元素o在List中最后一次出现的位置
int lastIndexOf(Object o);

ListIterator listIterator();

1
2
//返回List的List迭代
ListIterator<E> listIterator();

ListIterator listIterator(int index);

1
2
//返回List数组从index开始的list迭代
ListIterator<E> listIterator(int index);

List subList(int fromIndex, int toIndex);

1
2
//保留list中位置从fromIndex到toIndex的元素
List<E> subList(int fromIndex, int toIndex);