Java EnumSet.copyOf(Collection <E> c)
Syntax
EnumSet.copyOf(Collection <E> c) has the following syntax.
public static <E extends Enum <E>> EnumSet <E> copyOf(Collection <E> c)
Example
In the following code shows how to use EnumSet.copyOf(Collection <E> c) method.
/*from w ww . jav a 2 s.c o m*/
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
enum Numbers {
ONE, TWO, THREE, FOUR, FIVE
};
public class Main {
public static void main(String[] args) {
// create a new collection
Collection collection = new ArrayList();
// print the collection
System.out.println("Colletion :" + collection);
// add two elements in the collection
collection.add(Numbers.ONE);
collection.add(Numbers.THREE);
// create an EnumSet that is a copy of the collection
EnumSet<Numbers> set = EnumSet.copyOf(collection);
System.out.println(set);
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »