Java Program to Create an Enumset Collection

You are currently viewing Java Program to Create an Enumset Collection

Java program to create an EnumSet collection

// Java program to create an EnumSet collection

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.of(COLORS.BLUE, COLORS.BLACK, COLORS.GREEN, COLORS.WHITE);

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

Output

EnumSet is: [GREEN, BLUE, BLACK, WHITE]

Ranjith

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

Leave a Reply