Java tutorial
//package com.java2s; import java.util.*; public class Main { private static <T extends Comparable<T>> T getExtremum(Collection<T> vals, int comparator) { if (vals.size() == 0) return null; Iterator<T> it = vals.iterator(); T ret = it.next(); while (it.hasNext()) { T v = it.next(); if (v.compareTo(ret) * comparator > 0) ret = v; } return ret; } }