@Override
    @SuppressWarnings("unchecked")
    public <T> T[] toArray(T[] destArray) {
        int size = wrapperSet.size();
        if (destArray.length < size) {
            return (T[]) toArray();
        }

        Iterator<CharSequence> iter = iterator();
        int ind = 0;
        while (iter.hasNext()) {
            destArray[ind] = (T) iter.next();
            ind += 1;
        }

        if (destArray.length > size) {
            destArray[size] = null;
        }

        return destArray;
    }
Copied from iceberg 1.1.x. Modify Set to concurrent Set.
inlong-sort/sort-flink/sort-flink-v1.13/sort-connectors/iceberg/src/main/java/org/apache/inlong/sort/iceberg/sink/trick/CharSequenceSet.java