Java Collection Tutorial - Java EnumSet.clone()








Syntax

EnumSet.clone() has the following syntax.

public EnumSet <E> clone()

Example

In the following code shows how to use EnumSet.clone() method.

//from   w  w w  . ja v a 2 s  .c om

import java.util.EnumSet;
   
enum Numbers {

   ONE, TWO, THREE, FOUR, FIVE
};
public class Main {

   public static void main(String[] args) {

      EnumSet<Numbers>  set1 = EnumSet.allOf(Numbers.class);

      System.out.println("Set1:" + set1);

      EnumSet<Numbers>  set2 = set1.clone();

      System.out.println("Set2:" + set2);

   }
}

The code above generates the following result.