Thursday, June 3, 2010

Iterator Vs Enumerator

1. By using iterator we can remove the value but in ennumerator we can't.

2. Enumeration is twice as fast as Iterator and uses very less memory.

3. Iterator is much safer as compared to Enumeration b’ coz it always denies other threads to modify the collection object which is being iterated by it. Whenever a second thread tries for that Iterator will throw a ConcurrentModificationException. Iterators that do this are known as fail-fast iterators as they fail quickly and cleanly

1 comment:

  1. The functionality of Enumeration interface is duplicated by the Iterator interface.
    Iterator has a remove() method while Enumeration doesn't. Enumeration acts as Read-only interface, because it has the methods only to traverse and fetch the objects, where as using Iterator we can manipulate the objects also like adding and removing the objects. I have also blogged about
    difference between iterator and enumeration here.

    ReplyDelete