Java tutorial
import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.Set; import java.util.TreeSet; public class Main { public static void main(final String[] args) { sortDates(Arrays.asList(new DAY[] { DAY.MON, DAY.WED, DAY.TUE, DAY.THU, DAY.SUN, DAY.SAT, DAY.FRI })); } public static void sortDates(final List<DAY> dayList) { final Set<DAY> set = new TreeSet<DAY>(); set.addAll(dayList); for (final DAY day : set) { System.out.println(day); } } } enum DAY implements Comparable<DAY> { MON("MONDAY", 1), TUE("TUESDAY", 2), WED("WEDNESDAY", 3), THU("THURSDAY", 4), FRI("FRIDAY", 5), SAT("SATURDAY", 6), SUN("SUNDAY", 0); private String name; private int index; DAY(String name, int index) { name = name; index = index; } public String getName() { return name; } public int getIndex() { return index; } } class DAYComparator implements Comparator<DAY> { @Override public int compare(final DAY o1, final DAY o2) { int returnValue = 0; if (o1.getIndex() > o2.getIndex()) { returnValue = 1; } else if (o1.getIndex() < o2.getIndex()) { returnValue = -1; } return returnValue; } }