The EnumSet class is a specialized Set implementation in Java that is designed to work with enum types. It provides a high-performance implementation of Set for enums, taking advantage of the fact that enums are a finite, well-defined set of values.
import java.util.*; public class EmptyNot_Enum { public static void main(String[] args) { EnumSet < WEEKDAY > enum_set1 = EnumSet.noneOf(WEEKDAY.class); EnumSet < WEEKDAY > enum_set2; enum_set2 = EnumSet.range(WEEKDAY.Wednesday, WEEKDAY.Saturday); if (enum_set1.isEmpty()) { System.out.println("EnumSet 1 is an Empty"); } else { System.out.println("EnumSet 1 is not an Empty"); } if (enum_set2.isEmpty()) { System.out.println("EnumSet 2 is an Empty"); } else { System.out.println("EnumSet 2 is not an Empty"); } } } enum WEEKDAY { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday };
EnumSet 1 is an Empty EnumSet 2 is not an Empty
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions