Monday, 13 July 2020

Enumeration in Java with Example | Enumeration in Java explained with Program Code

                  In this post, we will see Enumeration in Java with Example | Enumeration in Java explained with Program Code



Watch this video to know Enumeration in Java with example of Java Program Code:



Watch on YouTube: https://www.youtube.com/watch?v=whJ2N1W4m2M

Program Code: (EnumerationProg.java) 



import java.util.Vector;
import java.util.Enumeration;

public class EnumerationProg {

   public static void main(String args[]) {
      Enumeration e;
      Vector months = new Vector();
     
      months.add("Jan");
      months.add("Feb");
      months.add("March");
      months.add("April");
      months.add("May");
      months.add("June");
      months.add("July");
      months.add("Aug");
      months.add("Sept");
      months.add("Oct");
      months.add("Nov");
      months.add("Dec");
     
      e = months.elements();
     
      while (e.hasMoreElements()) {
         System.out.println(e.nextElement());
      }
   }
}
  


Output:
parag@parag-Inspiron-N4010:~/Desktop/prog$ javac EnumerationProg.java
Note: EnumerationProg.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
parag@parag-Inspiron-N4010:~/Desktop/prog$ java EnumerationProg
Jan
Feb
March
April
May
June
July
Aug
Sept
Oct
Nov
Dec
 

No comments:

Post a comment