package devmanuals.com; import java.util.EnumSet; public final class EnumSetDemo { private enum Workingday { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday; public static final EnumSet Workdays = EnumSet.range( Monday, Friday); public final boolean isWorkday() { return Workdays.contains(this); } public static final EnumSet WHOLE_WEEK = EnumSet .allOf(Workingday.class); } public static final void main(final String args[]) { System.out.println("Workday Schedule:"); for (final Workingday workingday : Workingday.WHOLE_WEEK) System.out.println(String.format("%d. On %s you " + (workingday.isWorkday() ? "have to work" : "can relax") + ".", workingday.ordinal() + 1, workingday)); System.out.println("Do I have to work the whole week?"); System.out.println(Workingday.Workdays .containsAll(Workingday.WHOLE_WEEK) ? "Yes, unfortunately." : "Certainly not."); final EnumSet weekend = Workingday.WHOLE_WEEK.clone(); weekend.removeAll(Workingday.Workdays); System.out.println(String.format("The weekend is %d days long.", weekend.size())); } }