Java Core & Fundamentals Tutorial
Java tutorial for beginners on Java 25. Install the JDK, run a first program and follow a 12-step learning path plus an index of every Java topic.
In Java, an enum (short for “enumeration”) is a special data type that defines a set of named constants, also known as enum constants or enumerators. Enumerations provide a way to define a finite set of values that a variable can take on.
Enum constants are typically used to represent a predefined list of related values or options.
Java tutorial for beginners on Java 25. Install the JDK, run a first program and follow a 12-step learning path plus an index of every Java topic.
Create a Java enum with multiple values per constant, read them with getters, and find the constant from any value with a cached map and Optional.
Learn to create a Java enum with String values, convert an enum to a String with name(), toString() or a getter, and convert a String back to an enum safely with valueOf() or a case-insensitive lookup that returns Optional.
An enum is a data type with a fixed set of named constants. This Java enum tutorial covers declaring enums, values(), valueOf(), ordinal() and name(), switch and pattern matching on Java 25, constructors, fields and methods, EnumSet, EnumMap, singletons and safe String-to-enum conversion.
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.