public E set(int index, E element) { final ReentrantLock lock = this.lock; lock.lock(); try { Object[] elements = getArray(); E oldValue = get(elements, index);
if (oldValue != element) { int len = elements.length; Object[] newElements = Arrays.copyOf(elements, len); newElements[index] = element; setArray(newElements); } else { // Not quite a no-op; ensures volatile write semantics setArray(elements); } return oldValue; } finally { lock.unlock(); } }
add(E e) 元素添加到末尾
1
public boolean add(E e) {}
add(int index, E element) 指定位置之后插入元素
1
public void add(int index, E element){}
remove(int index)删除指定位置的元素
1
public E remove(int index) {}
remove(Object o) 删除第一个匹配的元素
1
public boolean remove(Object o) {}
removeRange(int fromIndex, int toIndex) 删除指定区间的元素
1
private void removeRange(int fromIndex, int toIndex) {}
addIfAbsent(E e) 如果元素不存在就添加进list中
1
public boolean addIfAbsent(E e){}
containsAll(Collection<?> c)是否包含全部
1
public boolean containsAll(Collection<?> c){}
removeAll(Collection<?> c) 移除全部包含在集合中的元素
1
public boolean removeAll(Collection<?> c){}
retainAll(Collection<?> c) 保留指定集合的元素,其他的删除
1
public boolean retainAll(Collection<?> c){}
addAllAbsent(Collection<? extends E> c) 如果不存在就添加进去
1
public int addAllAbsent(Collection<? extends E> c) {}
clear() 清空list
1
public void clear(){}
addAll(Collection<? extends E> c)添加集合中的元素到尾部
1
public void addAll(Collection<? extends E> c){}
addAll(int index, Collection<? extends E> c) 添加集合中元素到指定位置之后
1
public boolean addAll(int index, Collection<? extends E> c){}
toString()
1
public String toString(){}
equals(Object o)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof List)) return false;
List<?> list = (List<?>)(o); Iterator<?> it = list.iterator(); Object[] elements = getArray(); int len = elements.length; for (int i = 0; i < len; ++i) if (!it.hasNext() || !eq(elements[i], it.next())) return false; if (it.hasNext()) return false; return true; }
hashCode()
1
public int hashCode{}
listIterator(final int index)和 listIterator() 返回一个迭代器,支持向前和向后遍历
1 2 3
public ListIterator<E> listIterator(final int index) {}
public ListIterator<E> listIterator() {}
iterator() 只能向后遍历
1
public Iterator<E> iterator() {}
subList() 返回部分list
1 2 3 4 5
public List<E> subList(int fromIndex, int toIndex) { ... return new COWSubList<E>(this, fromIndex, toIndex); ... }