Saturday, 10 June 2017

Java Tutorial: Enum in java [How to get all values of Java enum -Level] ~ foundjava


Click here to watch in Youtube :

https://www.youtube.com/watch?v=_hAxSheXrCw&list=UUhwKlOVR041tngjerWxVccw

Level.java 

public enum Level
{
    HIGH, MEDIUM, LOW
}
EnumDemo.java 
public class EnumDemo
{

    public static void main(String[] args)
    {
        /*
         * We can obtain an array of all the possible values
         * of a Java enum type by calling its static
         * values() method.
         * 
         * All enum types get a static values() method
         * automatically by the Java compiler.
         * 
         * Notice the output how the names of the constants
         * themselves are printed out. This is one area
         * where Java enums are different than static final
         * constants.
         */
        
        Level[] levelArray = Level.values();
        
        for (Level level : levelArray)
        {
            System.out.println(level);
        }
    }
}
Output 
HIGH
MEDIUM
LOW
Click the below link to download the code:

CLICK HERE

No comments:

Post a Comment