public Object[] toArray(){
  final Object[] items=this.items;
  final ReentrantLock lock=this.lock;
  lock.lock();
  try {
    final int count=this.count;
    Object[] a=new Object[count];
    int n=items.length - takeIndex;
    if (count <= n) {
      System.arraycopy(items,takeIndex,a,0,count);
    }
 else {
      System.arraycopy(items,takeIndex,a,0,n);
      System.arraycopy(items,0,a,n,count - n);
    }
    return a;
  }
  finally {
    lock.unlock();
  }
}

public Object [ ] toArray ( ) { final Object [ ] items = this . items ; final ReentrantLock lock = this . lock ; lock . lock ( ) ; try { final int count = this . count ; Object [ ] a = new Object [ count ] ; int n = items . length - takeIndex ; if ( count <= n ) { System . arraycopy ( items , takeIndex , a , 0 , count ) ; } else { System . arraycopy ( items , takeIndex , a , 0 , n ) ; System . arraycopy ( items , 0 , a , n , count - n ) ; } return a ; } finally { lock . unlock ( ) ; } }
returns an array containing all of the elements in this queue , in proper sequence . < p > the returned array will be " safe " in that no references to it are maintained by this queue . ( in other words , this method must allocate a new array ) . the caller is thus free to modify the returned array . < p > this method acts as bridge between array - based and collection - based apis .
