Difference between Enumeration and Iterator can be summarized with the help of following points:
Enumerationis a legacy interface used to traverse only the legacy classes likeVectorandHashTable.Iteratoris not a legacy interface.Iteratorcan be used for the traversal of collections like HashMap, LinkedList, ArrayList, HashSet, TreeMap, TreeSet etc.Enumerationhas read-only access to the elements in the collection. On the other side,Iteratorcan remove the elements from the collection.Enumerationis not a universal cursor as it applies only to legacy classes.Iteratoris a universal cursor as it is applicable for all the collection classes.Enumerationwas added to the jdk1.0 version whileIteratorwas added in jdk1.2 version.Enumerationis fail-safe in nature. It does not throwConcurrentModificationExceptionif collection is modified during the traversal. Iterator is fail-fast in nature. It throwsConcurrentModificationExceptionif a collection is modified while iterating other than its ownremove()method.Enumerationhas methodshasMoreElements()andnextElement().Iteratorhas methodshasNext(),next()andremove().
Both Iterator and Enumeration are available in java.util package. Both Iterator and Enumerations are unidirectional forward access cursor.
According to Java API Docs, Iterator is always preferred over the Enumeration.
NOTE: The functionality of this interface is duplicated by the Iterator interface. In addition, Iterator adds an optional remove operation, and has shorter method names. New implementations should consider using Iterator in preference to Enumeration.
