import java.util.EnumSet; public class Example { enum Language { ENGLISH, SPANISH, FRENCH, GERMAN }; public static void main(String[] args) { EnumSetlanguageSet = EnumSet.of(Language.ENGLISH, Language.SPANISH); } }
import java.util.EnumSet; import java.time.DayOfWeek; public class Example { public static void main(String[] args) { EnumSetHere, we import the `DayOfWeek` enum from the `java.time` package and create an EnumSet `weekdays` which includes all the weekdays from Monday to Friday. We do this using the `range()` method. Overall, EnumSet is a useful class for creating sets of enumerated values, and it is a part of the Java Collections Framework, specifically the java.util package.weekdays = EnumSet.range(DayOfWeek.MONDAY, DayOfWeek.FRIDAY); } }