Difference between Iterator and Enumeration

enumertaion is there from Older versions (its there from JDK1.0).
But iteratr was introduced in later versions.
The major difference between Enumerator and Iterator is remove method.
remove() is there in Iterator.But it's not there in Enumerator.
Another Difference is Iterator is more secured than Enumerator.
Because It does not allow other thread while one thread is iterating the collection objects.

Enumeration :
hasMoreElement()
nextElement()

Iterator :
hasNext()
next()
remove()

so,Enumeration is used when u want to iterate the collection object without any removing of elements.



0 Response to "Difference between Iterator and Enumeration"

Post a Comment