code: public KType[] toArray(KType[] target) {
      assert target.length >= size() : "Target array must be >= " + size();
  
      if (head < tail) {
        // The contents is not wrapped around. Just copy.
        System.arraycopy(buffer, head, target, 0, size());
      } else if (head > tail) {
        // The contents is split. Merge elements from the following indexes:
        // [head...buffer.length - 1][0, tail - 1]
        final int rightCount = buffer.length - head;
        System.arraycopy(buffer, head, target, 0, rightCount);
        System.arraycopy(buffer, 0, target, rightCount, tail);
      }
  
      return target;
    }
docs: Copies elements of this deque to an array. The content of the
  <code>target</code> array is filled from index 0 (head of the queue) to
  index <code>size() - 1</code> (tail of the queue).
  
  @param target
  The target array must be large enough to hold all elements.
  @return Returns the target argument for chaining.