EnumSet in Java

Last Updated : 15 Oct, 2025

In Java, the EnumSet is a specialized set implementation for use with enum types. It is a part of java.util package and provides a highly optimized set for storing enum constants. The EnumSet is one of the specialized implementations of the Set interface for use with the enumeration type.

Example: This example demonstrates how to create an EnumSet and print its elements

Java
// Creating an EnumSet
import java.util.EnumSet;

enum Student { Geek1, Geek2, Geek3, Geek4, Geek5 }

public class Geeks {
    public static void main(String[] args) {
        
        // Create an EnumSet containing specific elements
        EnumSet<Student> e = EnumSet.of(Student.Geek1, Student.Geek2, Student.Geek3);

        System.out.println("EnumSet: " + e);
    }
}

Output
EnumSet: [Geek1, Geek2, Geek3]

Hierarchy of EnumSet

The Hierarchy of EnumSet is as follows: