Tuesday, January 18, 2011

What is the difference between Enumeration and Iterator ?

This question is from early ages of interview , I have not seen this question on recent interviews but it was common during 2006-2007 , now days questions like implementation of HashMap, ConcurrentHashMap etc has take its place, nonetheless its very useful
to know fundamental difference between this two.

Between two Enumeration is older and its there from jdk 1.0 while iterator was introduced later.
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.

Read more: TIBCO RV FIX PROTOCOL JAVA TUTORIAL