docs: @Override
     public <T> T[] toArray(T[] a) {
        // Estimate size of array; be prepared to see more or fewer elements
        int size = size();
        T[] r = a.length >= size ? a :
              (T[])java.lang.reflect.Array
                    .newInstance(a.getClass().getComponentType(), size);
        try (CloseableIterator<O> it = iterator()) {
           for (int i = 0; i < r.length; i++) {
              if (! it.hasNext()) { // fewer elements than expected
                 if (a == r) {
                    r[i] = null; // null-terminate
                 } else if (a.length < i) {
                    return Arrays.copyOf(r, i);
                 } else {
                    System.arraycopy(r, 0, a, 0, i);
                    if (a.length > i) {
                       a[i] = null;
                    }
                 }
                 return a;
              }
              r[i] = (T)it.next();
           }
           // more elements than expected
           return it.hasNext() ? finishToArray(r, it) : r;
        }
     }