@SuppressWarnings({"unchecked", "rawtypes"})
public static <T> T max (Collection<? extends T> coll, Comparator<? super T> comp)

Returns the maximum element of the given collection, according to the order induced by the specified comparator. All elements in the collection must be mutually comparable by the specified comparator (that is, comp.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the collection).

This method iterates over the entire collection, hence it requires time proportional to the size of the collection.

Parameters:
<T>    the class of the objects in the collection
coll    the collection whose maximum element is to be determined.
comp    the comparator with which to determine the maximum element. A null value indicates that the elements' natural ordering should be used.

Returns:  the maximum element of the given collection, according to the specified comparator.

Exceptions:
ClassCastException    if the collection contains elements that are not mutually comparable using the specified comparator.
NoSuchElementException    if the collection is empty.

See also:
Comparable