code: public int set(int i, int val) {
      checkIndex(i);
      int old = buf[i];
      buf[i] = val;
      return old;
    }
docs: Sets the value at index {@code i} to {@code val}.
  
  @param i the 0 - based index.
  @param val the new value.
  @return the old value.
  @throws ArrayIndexOutOfBoundsException if {@code i &lt; 0 or i >= size()}.