Java Program to Create a Clone of an Enumset Collection

Java program to create a clone of an EnumSet collection

// Java program to create a clone of 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;
    EnumSet < COLORS > clone;

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

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

    clone = enumSet.clone();
    System.out.println("Clone of enumSet is: " + clone);
  }
}

Output

EnumSet is: [RED, GREEN, BLUE, BLACK, WHITE]
Clone of enumSet is: [RED, GREEN, BLUE, BLACK, WHITE]
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