In this post, we will understand the difference between iterator and enumeration interfaces in Java.
Iterator
It is a universal cursor.
It can be applied to all collection of classes.
It contains the ‘remove’ method.
It is not a legacy interface.
It can be used to traverse over HashMap, LinkedList, ArrayList, HashSet, TreeMap, and TreeSet .
It can perform modifications to perform operations on the collection while traversing through it.
Enumeration
It is not a universal cursor.
It is applied only to legacy classes.
It doesn’t contain the ‘remove’ method.
It is a legacy interface.
This interface acts like a read-only interface.
Hence, no modifications can be performed on a collection while traversing over the elements in a Collection.
It can be used to traverse over Vectors, and Hashtable.