Java EnumSet.copyOf(EnumSet <E> s)
Syntax
EnumSet.copyOf(EnumSet <E> s) has the following syntax.
public static <E extends Enum <E>> EnumSet <E> copyOf(EnumSet <E> s)
Example
In the following code shows how to use EnumSet.copyOf(EnumSet <E> s) method.
/*from w ww .j av a 2 s . co m*/
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);
// create a second set which is a copy of set1
EnumSet<Numbers> set2 = EnumSet.copyOf(set1);
System.out.println("Set2:" + set2);
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »