Click here to watch in Youtube :
https://www.youtube.com/watch?v=CKfZ45TtkbI&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial: Enum in java | Java enum |
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); } } }Output
SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAYEnumDemo2.java
public 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); } } }Output
NORTH SOUTH EAST WESTEnumDemo3.java
public 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); } } }Output
WINTER SPRING SUMMER FALLRefer:
https://docs.oracle.com/javase/8/docs/api/java/lang/Enum.html
Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/EnumDemo_Intro_App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/EnumDemo_Intro_App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/2f1fa585daa61fc8fa0957d6f04b940eddbcf7ec/BasicJava/EnumDemo_Intro_App/?at=master
See also:
No comments:
Post a Comment