Java Program to Remove All Elements of Enumset Collection

You are currently viewing Java Program to Remove All Elements of Enumset Collection

Java program to remove all elements of EnumSet collection

// Java program to remove all elements of 
// 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 = EnumSet.noneOf(COLORS.class);

    enumSet.add(COLORS.RED);
    enumSet.add(COLORS.GREEN);
    enumSet.add(COLORS.BLUE);

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

    enumSet.clear();
    System.out.println("Elements of enumSet is: " + enumSet);
  }
}

Output

Elements of enumSet is: [RED, GREEN, BLUE]
Elements of enumSet is: []

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