Back to Top

Sunday, 15 January 2012

JAVA : What is an Iterator? How is it differ from enumerations?


    
   Some of the collection classes provide traversal of their contents via a java.util.Iterator interface. This interface allows you to walk through a collection of objects, operating on each object in turn. Remember when using Iterators that they contain a snapshot of the collection at the time the Iterator was obtained; generally it is not advisable to modify the collection itself while traversing an Iterator.
                             

   Iterators differ from enumerations in two ways:
  • Iterators allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics.
  • Method names have been improved.

1 Responses to “ JAVA : What is an Iterator? How is it differ from enumerations? ”

Arunava Saha said...
25 July 2014 at 17:42

One more - Iterator is Fail-Fast whereas Enumerator is Fail-Safe


Post a Comment

Popular Posts

Subscribe via Email
Subscribe Java Interview Questions via Email
All Rights Reserved JAVA INTERVIEW QUESTIONS | Privacy Policy | Anijit Sarkar