public class EnumDemo1
{
public enum Day
{
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
}
public static void main(String[] args)
{
/*
* The java compiler internally adds the values()
* method when it creates an enum. The values()
* method returns an array containing all the values
* of the enum.
*/
Day[] daysArray = Day.values();
for (Day day : daysArray)
{
System.out.println(day);
}
}
}
OutputSUNDAY
MONDAY
TUESDAY
WEDNESDAY
THURSDAY
FRIDAY
SATURDAY
EnumDemo2.javapublic class EnumDemo2
{
public enum Direction
{
NORTH, SOUTH, EAST, WEST
}
public static void main(String[] args)
{
/*
* The java compiler internally adds the values()
* method when it creates an enum. The values()
* method returns an array containing all the values
* of the enum.
*/
Direction[] directionsArray = Direction.values();
for (Direction direction : directionsArray)
{
System.out.println(direction);
}
}
}
OutputNORTH
SOUTH
EAST
WEST
EnumDemo3.javapublic class EnumDemo3
{
public enum Season
{
WINTER, SPRING, SUMMER, FALL
}
public static void main(String[] args)
{
/*
* The java compiler internally adds the values()
* method when it creates an enum. The values()
* method returns an array containing all the values
* of the enum.
*/
Season[] seasonArray = Season.values();
for (Season season : seasonArray)
{
System.out.println(season);
}
}
}
OutputWINTER
SPRING
SUMMER
FALL
Refer: https://docs.oracle.com/javase/8/docs/api/java/lang/Enum.htmlClick the below link to download the code:https://sites.google.com/site/ramj2eev1/home/javabasics/EnumDemo_Intro_App.zip?attredirects=0&d=1Github Link:https://github.com/ramram43210/Java/tree/master/BasicJava/EnumDemo_Intro_AppBitbucket Link:https://bitbucket.org/ramram43210/java/src/2f1fa585daa61fc8fa0957d6f04b940eddbcf7ec/BasicJava/EnumDemo_Intro_App/?at=masterSee also: All JavaEE Viedos PlaylistAll JavaEE ViedosAll JAVA EE LinksServlets TutorialAll Design Patterns LinksJDBC TutorialJava Collection Framework TutorialJAVA TutorialKids Tutorial