Enum is the Java enumeration class. Think of it as being able to replace the class keyword. It started with JDK5.

Value conventions in enumerated classes are capitalized, separated by commas, and are static final by default, such as:

enum Gender {
    MALE, FEMALE
}
Copy the code

Enumeration classes have two main uses

  1. Both MALE and FEMALE data types are Gender. So enums can restrict a set of values to a type, such as MALE and FEMALE to Gender.

  2. Enum can also define all values that can be retrieved from a class, such as MALE and FEMALE.

Enum can be thought of as a reference datatype “with basic datatype properties,” and therefore can be checked for equality by “==” rather than by equals(). Equals () also works, just a little more code.