Java.util.EnumSet.of() 方法示例


Java.util.EnumSet.of() 方法示例

/*This example is using a method called main2
to simulate calling the main method using args
from a command line.*/

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 fake list that will be used like args
      Numbers[] list = {Numbers.ONE, Numbers.THREE, Numbers.FOUR, Numbers.FIVE};

      // call the fake main
      main2(list);
   }

   // This is a fake main. This is used as an example
   public static void main2(Numbers[] fakeargs) {

      // create a set
      EnumSet<Numbers> set;

      // add first element and the rest of fakeargs
      set = EnumSet.of(Numbers.ONE, fakeargs);

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