Let's say
Enum MyClass { ORANGE, APPLE, BANANA; }
In this case this will be true:
ORANGE.compareTo(APPLE)<0
and Collections.min()
would give me ORANGE
If I have
private static final String[] values = {ORANGE, APPLE, BANANA};
Is there a way to return same result.
I tried using Collections.min(values)
, but the answer was APPLE, because it was using natural order.
I tried using this
public static <T> T min(Collection<? extends T> coll,Comparator<? super T> comp)
so that it returns the minimum element of the given collection, according to the order induced by the specified comparator.
If I want to have above result, how do I define the Comparator?