From the course: Java 8+ Essential Training: Objects and APIs

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Declare and use enum types

Declare and use enum types - Java Tutorial

From the course: Java 8+ Essential Training: Objects and APIs

Start my 1-month free trial

Declare and use enum types

- [Instructor] Java supports a special type called an enum, short for an enumeration. An enum lets you define a set of mutually exclusive values that can be referenced throughout an application. Just like variables that are static and final, constants, an enum value can only be defined once. Enum values are stored internally as integer values. But like the constants that I've previously shown, those values don't matter. What matters is that each enumerated value is unique. In this application, I'll go to my utilities package, and select new, java class. I'll call the class operation, but instead of it being a class, I'll choose enum as the type. I'll click okay. And that creates the enum file. Just like a class, the identifier, that is the enum has to match the name of the file. So, the enum operation is stored in operation dot java. Now, to define the available values, I'll type in add, comma subtract, and then a semicolon, and that's all you need to do. The actual values will be…

Contents