AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



corejava-collection: What is the difference between Iterator and Enumeration?

Please explain the difference between Iterator and enumeration with example.

corejava x 353
collection x 52
Posted On : 2014-04-14 19:35:05.0
profile Saksham Kumar - anyforum.in Saksham Kumar
73433939091
up-rate
5
down-rate

Answers


Enumeration is older than Iterator, it was introduce since JDK1.0 . Iterator is used with Java arraylist, hashmap keyset and with other collection classes.

Functionality of Enumeration interface is inherited in Iterator Interface. Let´s see the major difference Enumeration and Iterator.
1. Iterator has remove() method while Enumeration does not have.

2. Enumeration works like Read-only interface, because it has the methods to traverse and fetch the objects, while Iterator can manipulate the objects like adding and removing the objects from collection.

3. Iterator is more secure and safe as compared to Enumeration because it does not allow other thread to modify the collection object while some thread is iterating over it and throws ConcurrentModificationException.

4. Iterator is newer and improved version where method names are shorter, and has new method called remove.

Posted On : 2014-04-14 21:00:16
Satisfied : 1 Yes  0 No
profile Garima Gupta - anyforum.in Garima Gupta
596129558962
Reply This Thread
up-rate
5
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in