public static < T > Iterator < T > toSorted ( Iterator < T > self , Comparator < T > comparator ) { return toSorted ( toList ( self ) , comparator ) . listIterator ( ) ; }
Sorts the given iterator items using the comparator . The original iterator will become exhausted of elements after completing this method call . A new iterator is produced that traverses the items in sorted order .