You can use the new class java.util.EnumSet to create a set of enums and the new class java.util.EnumMap to create a map that uses enums as keys.
Here is some code illustrating two uses of EnumSet:
0472: Day tToday = Day.Wednesday; 0473: Day[] tDayValues = Day.values(); 0474: for (int tDayNumber = Day.Tuesday.ordinal(); 0475: tDayNumber<=Day.Thursday.ordinal(); tDayNumber++) 0476: { 0477: Day tDay = tDayValues[tDayNumber]; 0478: System.out.println(tDay + " " + tDay.compareTo(tToday)); 0479: } 0480: for (Day tDay : EnumSet.range(Day.Tuesday, Day.Thursday)) 0481: { 0482: System.out.println(tDay + " " + tDay.compareTo(tToday)); 0483: } 0484: for (Day tDay : Day.values()) 0485: { 0486: if (tDay.toString().length()==6) 0487: { 0488: System.out.println(tDay + " is a 6 letter day"); 0489: } 0490: } 0491: for (Day tDay : Day.values()) 0492: { 0493: if (EnumSet.of(Day.Sunday, Day.Monday, Day.Friday).contains(tDay)) 0494: { 0495: System.out.println(tDay + " is a 6 letter day"); 0496: } 0497: }
The above code produces the output:
0511: Tuesday -1 0512: Wednesday 0 0513: Thursday 1 0514: Tuesday -1 0515: Wednesday 0 0516: Thursday 1 0517: Sunday is a 6 letter day 0518: Monday is a 6 letter day 0519: Friday is a 6 letter day 0520: Sunday is a 6 letter day 0521: Monday is a 6 letter day 0522: Friday is a 6 letter day