Enums in Java

From the Java cheat sheet · Enums · verified Jul 2026

Enums

Simple constants and enums with fields and methods.

java
// Quick Reference
enum Day { MON, TUE, WED }
Day d = Day.MON;
switch (d) { case MON -> ...; }
💡 Enums are type-safe - the compiler rejects any value outside the defined set.
⚡ Enum constructors are implicitly private and run once per constant.
📌 values() returns all constants; valueOf(name) parses one (throws if not found).
🟢 Give enums fields and methods to attach data and behavior to each constant.
enumsconstants

Continue with Java

Save the full cheat sheet or work through every related task.

Back to the full Java cheat sheet