0 day streak
java / beginner
Snippet

Java Enums

Enums are special types that represent a fixed set of constants, making code more readable and type-safe.

snippet.java
java
1
2
3
4
5
enum Priority {
LOW, MEDIUM, HIGH
}
Priority myLevel = Priority.MEDIUM;
Breakdown
1
enum Priority {
Defines a new enumeration type named Priority.
2
LOW, MEDIUM, HIGH
The predefined constants available in this Enum.
3
Priority myLevel = Priority.MEDIUM;
Assigns a specific Enum value to a variable.