Creates an enum set with the same element type as the specified enum set, initially containing all the elements of
this type that are not contained in the specified set.
package com.logicbig.example.enumset;
import java.time.DayOfWeek;
import java.util.EnumSet;
public class ComplementOfExample {
public static void main(String... args) {
EnumSet<DayOfWeek> originalSet = EnumSet.of(DayOfWeek.SATURDAY, DayOfWeek.SUNDAY);
System.out.println("original set: " + originalSet);
EnumSet<DayOfWeek> set = EnumSet.complementOf(originalSet);
System.out.println("complement of original: " + set);
}
}
Output
original set: [SATURDAY, SUNDAY]
complement of original: [MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY]