提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
如何使用EnumSet类
/*n o w j a v a . c o m - 时代Java 提 供*/ import java.util.EnumSet; enum Day { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY; } public class Main { public static void main(String[] args) { // Get all constants of the Day enum EnumSet<Day> allDays = EnumSet.allOf(Day.class); print(allDays, "All days: " ); // Get all constants from MONDAY to FRIDAY of the Day enum EnumSet<Day> weekDays = EnumSet.range(Day.MONDAY, Day.FRIDAY); print(weekDays, "Weekdays: "); EnumSet<Day> weekends = EnumSet.complementOf(weekDays); print(weekends, "Weekends: "); } public static void print(EnumSet<Day> days, String msg) { System.out.pri