Enumeration is used to retrieve or traverse all the elements of particular collection of objects. Its not considered for collections but we can use it for legacy like Vectors. To use it we need to import - Java.util.Enumeration
Below is the implementation :-
Enumeration enumDay;
Vector nameOfEnumDay = new Vector();
nameOfEnumDay.add("Sunday");
nameOfEnumDay.add("Monday");
nameOfEnumDay.add("Tuesday");
nameOfEnumDay.add("Wednesday");
nameOfEnumDay.add("Thursday");
nameOfEnumDay.add("Friday");
nameOfEnumDay.add("Saturday");
enumDay = nameOfEnumDay.elements();
while (enumDay.hasMoreElements()){
System.out.println(enumDay.nextElement());
}
}
}
Output :-
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
0 Comment(s)