public static < T > Iterator < T > getSortedIterator ( Iterator < T > itr , Comparator < T > comparator ) { SortableArrayList < T > list = new SortableArrayList < T > ( ) ; CollectionUtil . addAll ( list , itr ) ; list . sort ( comparator ) ; return getUnmodifiableIterator ( list ) ; }
Get an Iterator that returns the same elements returned by the supplied Iterator but in the order dictated by the supplied Comparator .