code: public static <T extends Comparable<? super T>> Iterator<T> getSortedIterator (Iterator<T> itr)
      {
          return getSortedIterator(itr, new Comparator<T>() {
              public int compare (T o1, T o2) {
                  if (o1 == o2) { // catches null == null
                      return 0;
                  } else if (o1 == null) {
                      return 1;
                  } else if (o2 == null) {
                      return -1;
                  }
                  return o1.compareTo(o2); // null-free
              }
          });
      }
docs: Get an Iterator that returns the same elements returned by the supplied Iterator, but in
  their natural order.