code: public Object[] toArray() {
          final ReentrantLock lock = this.lock;
          lock.lock();
          try {
              final Object[] items = this.items;
              final int end = takeIndex + count;
              final Object[] a = Arrays.copyOfRange(items, takeIndex, end);
              if (end != putIndex)
                  System.arraycopy(items, 0, a, items.length - takeIndex, putIndex);
              return a;
          } finally {
              lock.unlock();
          }
      }
docs: 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.
  
  @return an array containing all of the elements in this queue