@Override public void remove() { if (!canRemove) { throw new IllegalStateException(); } else { canRemove = false; list.remove(previous); } }
@Override public E2 set(int index, E2 element) { E2 oldElement = get(index); int oldModCount = modCount; if (oldElement != element) { remove(oldElement); add(index, element); } // After the remove and add the modCount would have been incremented twice modCount = oldModCount + 1; return oldElement; }
@Override public E2 remove(int index) { E2 elemToRemove = get(index); remove(elemToRemove); return elemToRemove; }