What is the exact difference between these two interfaces? Does Enumeration have benefits over using Iterator? If anyone could elaborate, a reference article would be appre
The main different is Enumeration doesn't expose remove() method. Moreover, Iterator don't allow a simultaneously navigation and modification on an underlying object. They have a control to see if there are concurrent modifications or so, and hence takes more processing. So Enumeration's performance is virtually 50% faster than Iterator. If we need only navigation ignoring such a synchronization, just use Enumeration.
Both iterator and enumeration are used to retrieve the data, the difference is that enumeration can be used only for legacy classes i.e vector/stack whereas iterators can be used for the rest. Enumeration can also be used for the key set in maps.
Enumeration can be used only for the legacy class(Vector, Stack...), while Iterator can be used for all.
One simple fact but haven't mentioned in previous answers is that Iterator<T>
is used with Iterable<T>
to serve in interpreting for(_type_ element:collection){...}
structure.