public <T> T[] toArrayHelper(T[] array, int offset) {
        final int N = colGetSize();
        if (array.length < N) {
            @SuppressWarnings("unchecked") T[] newArray
                    = (T[]) Array.newInstance(array.getClass().getComponentType(), N);
            array = newArray;
        }
        for (int i = 0; i < N; i++) {
            array[i] = (T) colGetEntry(i, offset);
        }
        if (array.length > N) {
            array[N] = null;
        }
        return array;
    }
Helper for writing standard Java collection interfaces to a data
structure like {@link ArrayMap}.
android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/util/collection/MapCollections.java