Java Program to Check Whether an Enumset Collection Is Empty or Not

Java program to check whether an EnumSet collection is empty or not

// Java program to check whether an EnumSet collection 
// is empty or not

import java.util.*;

//Enum for color constants
enum COLORS {
  RED,
  GREEN,
  BLUE,
  BLACK,
  WHITE
};

public class Main {
  public static void main(String[] args) {
    EnumSet < COLORS > enumSet1;
    EnumSet < COLORS > enumSet2 = EnumSet.noneOf(COLORS.class);

    enumSet1 = EnumSet.range(COLORS.GREEN, COLORS.BLACK);

    if (enumSet1.isEmpty())
      System.out.println("The enumSet1 is an empty EnumSet collection.");
    else
      System.out.println("The enumSet1 is not an empty EnumSet collection.");

    if (enumSet2.isEmpty())
      System.out.println("The enumSet2 is an empty EnumSet collection.");
    else
      System.out.println("The enumSet2 is not an empty EnumSet collection.");
  }
}

Output

The enumSet1 is not an empty EnumSet collection.
The enumSet2 is an empty EnumSet collection.
Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment