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


advertisement
 

Tip: Navigating an Enum

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


advertisement

WEBINAR:

On-Demand

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


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

*/

 

Visit the DevX Tip Bank

 





   
Sridhar M S. is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.
Thanks for your registration, follow us on our social networks to keep up-to-date