public void add(int index,E element){
  final ReentrantLock lock=this.lock;
  lock.lock();
  try {
    Object[] elements=getArray();
    int len=elements.length;
    if (index > len || index < 0)     throw new IndexOutOfBoundsException("Index: " + index + ", Size: "+ len);
    Object[] newElements;
    int numMoved=len - index;
    if (numMoved == 0)     newElements=Arrays.copyOf(elements,len + 1);
 else {
      newElements=new Object[len + 1];
      System.arraycopy(elements,0,newElements,0,index);
      System.arraycopy(elements,index,newElements,index + 1,numMoved);
    }
    newElements[index]=element;
    setArray(newElements);
  }
  finally {
    lock.unlock();
  }
}

public void add ( int index , E element ) { final ReentrantLock lock = this . lock ; lock . lock ( ) ; try { Object [ ] elements = getArray ( ) ; int len = elements . length ; if ( index > len || index < 0 ) throw new IndexOutOfBoundsException ( "Index: " + index + ", Size: " + len ) ; Object [ ] newElements ; int numMoved = len - index ; if ( numMoved == 0 ) newElements = Arrays . copyOf ( elements , len + 1 ) ; else { newElements = new Object [ len + 1 ] ; System . arraycopy ( elements , 0 , newElements , 0 , index ) ; System . arraycopy ( elements , index , newElements , index + 1 , numMoved ) ; } newElements [ index ] = element ; setArray ( newElements ) ; } finally { lock . unlock ( ) ; } }
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 ) .
