@Override public void add(int index,E element){
  if (index == 0) {
    addFirst(element);
    return;
  }
  if (index == size) {
    add(element);
    return;
  }
  rangeCheck(index);
  ensureCapacity(index,1);
  int realIndex=start + index;
  if (realIndex <= pivotIndex && (realIndex < (end - 1))) {
    System.arraycopy(buffer,start,buffer,start - 1,realIndex - start);
    start--;
    realIndex--;
  }
 else {
    System.arraycopy(buffer,realIndex,buffer,realIndex + 1,end - realIndex);
    end++;
  }
  buffer[realIndex]=element;
  size++;
}

@ Override public void add ( int index , E element ) { if ( index == 0 ) { addFirst ( element ) ; return ; } if ( index == size ) { add ( element ) ; return ; } rangeCheck ( index ) ; ensureCapacity ( index , 1 ) ; int realIndex = start + index ; if ( realIndex <= pivotIndex && ( realIndex < ( end - 1 ) ) ) { System . arraycopy ( buffer , start , buffer , start - 1 , realIndex - start ) ; start -- ; realIndex -- ; } else { System . arraycopy ( buffer , realIndex , buffer , realIndex + 1 , end - realIndex ) ; end ++ ; } buffer [ realIndex ] = element ; size ++ ; }
inserts the specified element at the specified position in this list . shifts the element currently at that position ( if any ) and any subsequent elements to the right ( adds one to their indices ) .
