Consider a collection consisting of enum types. Is there some library method min (or max) which accepts this collection (or varargs) and returns the smallest/highest value?
EDIT: I meant the natural order of enums, as defined by their compare implementation of Comparable.
Enums implement
Comparable<E>(whereE is Enum<E>) and their natural order is the order in which the enum constants are declared.You can use their default Comparable implementation to get the max and min constants as declared:
Then you can use:
Probably, a faster way would be to use direct access to the array returned by the
values()method:Note that the parameter given to the enum has no effect in the ordering.