Java.util.EnumSet.complementOf() 方法


Java.util.EnumSet.complementOf() 方法

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 an EnumSet that has only Numbers.FOUR as element
   EnumSet<Numbers> set1 = EnumSet.of(Numbers.FOUR);

   // print the set
   System.out.println("Set1:" + set1);

   // create a set2 which has all elements that set1 doesn't have
   EnumSet<Numbers> set2 = EnumSet.complementOf(set1);

   // print the updated set
   System.out.println("Set2:" + set2);

   }
}