Java.util.EnumSet.copyOf() 方法


Java.util.EnumSet.copyOf() 方法

package com.codingdict;

import java.util.*;

public class EnumSetDemo {

   // create an enum
   public enum Numbers {
      ONE, TWO, THREE, FOUR, FIVE
   };

   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);

      // print the set
      System.out.println("Set:" + set);
   }
}