Home » Tip Bank » Java
  • Comment on this Article
Language: Java
Expertise: Intermediate
Mar 19, 2020

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Watch

Navigating an Enum

Enums are predefined place holders in Java. Knowing the contents of an enum will be handy in many instances.

Take a look at how to navigate the elements of an enum:

public class NavigatingAnEnum
{
   public static void main(String args[])
   {
      NavigatingAnEnum navigatingAnEnum = new NavigatingAnEnum();
      navigatingAnEnum.proceed();
   }
   
   enum Criteria {
      LOW,
      MEDIUM,
      HIGH
   }
   
   private void proceed()
   {
      System.out.println("Elements of the enum Criteria...");
      for (Criteria criteria : Criteria.values()) {
         System.out.println(criteria);
      }
   }
}

/*

Expected output:

[root@mypc]# java NavigatingAnEnum
Elements of the enum Criteria...
LOW
MEDIUM
HIGH

*/
M S Sridhar
 
Submit a Tip
Browse "Java" Tips
Browse All Tips
javascriptweekly.com
codecademy.com