Early versions of java did not include Collections framework. Instead it defined several classes and one interface to store objects. When collection came these classes reengineered to support the Collection interfaces. These old classes are known are legacy classes.
Legacy classes-Dictionary,HashTable,Properties, Stack, Vector
Legacy interface- Enumeration.
• Enumeration ---Interface
• Dictonary ------Abstract class
• Hashtable -----Concrete class
• Properties -----Concrete class
• Vector -----Concrete class
• Stack -----Concrete class
Only values- Stack, Vector
Key/value pair – Dictionary, HashTable, Properties
Enumeration interface:
It defines the method by which we can enumerate(obtain one at a time) through the elements. The legacy interface is suppressed by Iterator.
It has two methods:
Boolean hasMoreElements()
nextElement()
what is difference between Enumeration and Iterator
ReplyDeleteCheck this,
Deletehttp://newjavafaqs.blogspot.in/2010/07/what-is-difference-enumeration-and.html
Both Iterator and Enumeration interfaces acts like cursors in collection.But Enumeration Interface is applied for only legacy classes(old classes) like vector and stack also with enumeration we can only read but with itereator we can also remove the elements....
Delete@Ashi: Do you know everything about java Ashi... nobody is perfect here and that is the reason you even come to this page... so stop dominating others...
ReplyDelete@Rekha: I only know two differences b/w Enumeration and Iterator
1) Enumeration has long name for methods but Iterator has short.
2) Enumeration does not have remove method which is present in Iterator.
I hope this will clear your issue. Best of luck.
very good Sudhanshu not for your explination for your attitude
DeleteThanks Sudhanshu,
DeleteI agree with Balaji
Also, Iterator is fail-safe
ReplyDelete@Ashi
ReplyDeletePlease avoid these kind of comments.
Or I will be forced to block you.
thanks ....
ReplyDelete