dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Mar 19, 2020

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
 
Thanks for your registration, follow us on our social networks to keep up-to-date