java中的enumset小结
java中的enumset其实是set的一个实现类了,但平常比较少用到,所以小结归纳下:
1 先定义一个枚举
public enum Seasons {
AUTMN,WINTER,SPRING,SUMMER
}
测试:
EnumSet seasons = EnumSet.range(Seasons.AUTUMN,Seasons.SPRING); for (Seasons season : seasons) { System.out.println("SEASONS:"+season.name()); } EnumSet complementEnumset = EnumSet.complementOf(seasons); for (Seasons season : complementEnumset) { System.out.println("SEASON:"+season.name()); }