docs: @Override
      public <T> T[] toArray(T[] a) {
          int size = size();
          if (a.length < size)
              a = (T[]) java.lang.reflect.Array.newInstance(
                      a.getClass().getComponentType(), size);
          if (head < tail) {
              System.arraycopy(elements, head, a, 0, size());
          } else if (head > tail) {
              int headPortionLen = elements.length - head;
              System.arraycopy(elements, head, a, 0, headPortionLen);
              System.arraycopy(elements, 0, a, headPortionLen, tail);
          }
          if (a.length > size)
              a[size] = null;
          return a;
      }