| Author |
Iterator Vs Enumerator
|
AJ sisodia
Greenhorn
Joined: Jan 19, 2005
Posts: 16
|
|
I take it both serve the same purpose. Enumeration interface has become obsolete but in case of HashTable enumerator would be preferred as HashTable does not directly support itertors. i would like to know can i altogether leave enumerator and can depend on iterator to access elements one by one. Why do we give preference to iterator over enumerator. What is the difference between the two if any.
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
|
http://www.coderanch.com/t/202139/Performance/java/Enumeration-vs-Iterator
|
[My Blog]
All roads lead to JavaRanch
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12952
|
|
It's Hashtable (lower case t), not HashTable. You should use HashMap instead of Hashtable, if possible. Hashtable is obsolete, just like interface Enumeration. If you are stuck with Hashtable and you want to use an iterator, you can easily write an adapter class that adapts an Enumeration to an Iterator (note, this is untested code):
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: Iterator Vs Enumerator
|
|
|