code: public Object[] toArray() {
          final int head = this.head;
          final int tail = this.tail;
          boolean wrap = (tail < head);
          int end = wrap ? tail + elements.length : tail;
          Object[] a = Arrays.copyOfRange(elements, head, end);
          if (wrap)
              System.arraycopy(elements, 0, a, elements.length - head, tail);
          return a;
      }
docs: Returns an array containing all of the elements in this deque
  in proper sequence (from first to last element).
  
  <p>The returned array will be "safe" in that no references to it are
  maintained by this deque.  (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 deque