I was just roaming through the API and it came to my attention that, Enumerations and Iterators aren’t very useful interfaces.
Specifically I mean, instead of saying (for Vector v):
for (Enumeration<E> e = v.elements(); e.hasMoreElements();)
System.out.println(e.nextElement());
We can easily say:
for (int i = 0; i < v.size(); i++)
System.out.println(v.elementAt(i));
What I wanted to know exactly is:
Are there any performance bonuses for using Enumerations/Iterators?
Has it provided you the ability to achieve something that cannot be achieved by the latter for loop?
I don’t think iterators and enumerations are about performance; they’re about better abstraction.
You don’t need to know anything about the underlying data structure if you have an iterator. That’s why I think that interface is perfectly acceptable. I don’t agree with your statement that Iterator isn’t a useful interface. What methods would you add?