Java tutorial
//package com.java2s; import java.util.Comparator; import java.util.Iterator; public class Main { public static <T extends Comparable<? super T>> T min(Iterator<? extends T> iterator) { T next, candidate = iterator.next(); while (iterator.hasNext()) { if ((next = iterator.next()).compareTo(candidate) < 0) { candidate = next; } } return candidate; } public static <T> T min(Iterator<? extends T> iterator, Comparator<T> comparator) { T next, candidate = iterator.next(); while (iterator.hasNext()) { if (comparator.compare(next = iterator.next(), candidate) < 0) { candidate = next; } } return candidate; } }