Java EnumSet.complementOf(EnumSet <E> s)

Syntax

EnumSet.complementOf(EnumSet <E> s) has the following syntax.

public static <E extends Enum <E>> EnumSet <E> complementOf(EnumSet <E> s)

Example

In the following code shows how to use EnumSet.complementOf(EnumSet <E> s) method.


//from   w w  w  .  j a  v  a2s .com


import java.util.EnumSet;

enum Numbers {

   ONE, TWO, THREE, FOUR, FIVE
};
public class Main {

   public static void main(String[] args) {

      EnumSet<Numbers>  set1 = EnumSet.of(Numbers.FOUR);

      System.out.println("Set1:" + set1);

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

      System.out.println("Set2:" + set2);

   }
}

The code above generates the following result.