Java Program to Create an Empty Enumset Using NoneOf() Method

Java Program to Create an Empty Enumset Using NoneOf() Method

Java Program to Create an Empty Enumset Using NoneOf() Method

// Java program to create an empty EnumSet 
// using noneOf() method

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 > enumSet;

    //Adding elements to EnumSet.
    enumSet = EnumSet.allOf(COLORS.class);

    System.out.println("EnumSet is: " + enumSet);

    EnumSet < COLORS > emptySet = EnumSet.noneOf(COLORS.class);

    System.out.println("Empty EnumSet is: " + emptySet);
  }
}
EnumSet is: [RED, GREEN, BLUE, BLACK, WHITE]
Empty EnumSet is: []

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

Share on:

Leave a Comment