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: []