Constructs a sublist of an arbitrary ArrayList. publicSubList(ArrayList<E> root, int fromIndex, int toIndex){ this.root = root; this.parent = null; this.offset = fromIndex; this.size = toIndex - fromIndex; this.modCount = root.modCount; }
Constructs a sublist of another SubList. privateSubList(SubList<E> parent, int fromIndex, int toIndex){ this.root = parent.root; this.parent = parent; this.offset = parent.offset + fromIndex; this.size = toIndex - fromIndex; this.modCount = parent.modCount; }
public E set(int index, E element); public E get(int index); publicintsize(); publicvoidadd(int index, E element); public E remove(int index); protectedvoidremoveRange(int fromIndex, int toIndex); .......
E set(int index, E element)
…
1 2 3 4 5 6 7
public E set(int index, E element){ Objects.checkIndex(index, size); checkForComodification(); E oldValue = root.elementData(offset + index); root.elementData[offset + index] = element; return oldValue; }
public E get(int index)
…
1 2 3 4 5
public E get(int index){ Objects.checkIndex(index, size); checkForComodification(); return root.elementData(offset + index); }
public E remove(int index){ Objects.checkIndex(index, size); checkForComodification(); E result = root.remove(offset + index); updateSizeAndModCount(-1); return result; }