public void sort(Comparator<E> comparator) {
        ArrayList<E> array = new ArrayList<>(size);
        Iterator<E> iterator = iterator();
        while (iterator.hasNext()) {
            E e = iterator.next();
            iterator.remove();
            array.add(e);
        }
        array.sort(comparator);
        for (E e : array) {
            add(e);
        }
    }
Returns a {@link Set} view of the elements contained in the collection. The
set is backed by the collection, so changes to the collection are reflected in
the set, and vice versa. The set supports element removal and addition, which
removes from or adds to the collection, respectively.

@return a set view of the elements contained in this collection
clients/src/main/java/org/apache/kafka/common/utils/ImplicitLinkedHashCollection.java