Java Enum

Java Enum is a data type which contains a set of constant values. The Enum can be used for Days, months and directions.

The enum values should be in all capital letter according to Java best practice.

The enum constants are static and final implicitly.

Enum can have fields, methods and constructors.

Example:

Below is the sample code for enum creation and print all its value using for loop.

Values(), valueOf() and ordinal() methods are present in java.lang.Eum

values() method will return all values present in enum.

valueOf() method return enum constant

ordinal() will return the enum index similar to as an Array.

OUTPUT:

Imran Khan

Specialist Master (Architect) with a passion for cutting-edge technologies like AEM (Adobe Experience Manager) and a proven track record of delivering high-quality software solutions.

  • Languages: Java, Python
  • Frameworks: J2EE, Spring, Struts 2.0, Hibernate
  • Web Technologies: React, HTML, CSS
  • Analytics: Adobe Analytics
  • Tools & Technologies: IntelliJ, JIRA

🌐 LinkedIn

📝 Blogs

📧 Imran Khan