Пример #1
0
  @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;
  }