views:

66

answers:

3

If enums are used from jdk1.5 onwards , what was the use of java.util.Enumeration interface before jdk1.5 ? Can anybody help me explore this with an example please ?

+3  A: 

Enum and java.util.Enumeration are unrelated.

codaddict
+1  A: 

java.util.Enumeration was the precursor to java.util.Iterator which was introduced in Java 1.2. Below is an example from the Javadoc of an Enumeration being used to iterate through a Vector

for (Enumeration<E> e = v.elements(); e.hasMoreElements();)
   System.out.println(e.nextElement());

It has nothing to do with Java 5 enums.

Mark
+5  A: 

Enumeration is an early Java class essentially replaced by Iterator. it is used for iteration of certain largely outdated collections.

Enums are Java's version of typesafe enums in the C/C++ sense. They represent a finite and fixed set of values that are canonical but can also have behaviour. They stem from the pattern established by Joshua Bloch in Effective Java.

In other words, they're not related.

cletus