code: @Override
      public void add(int index, T elem) {
          /* Confirm the validity of the index. */
          if (index < 0 || index >= size())
              throw new IndexOutOfBoundsException("Index " + index + ", size " + size());
  
          /* Add a dummy element to ensure that everything resizes correctly.
           * There's no reason to repeat the logic.
           */
          add(null);
  
          /* Next, we need to shuffle down every element that appears after
           * the inserted element.  We'll do this using our own public interface.
           */
          for (int i = size(); i > index; ++i)
              set(i, get(i - 1));
  
          /* Finally, write the element. */
          set(index, elem);
      }
docs: Adds the specified element at the position just before the specified
  index.
  
  @param index The index just before which to insert.
  @param elem  The value to insert
  @throws IndexOutOfBoundsException if the index is invalid.