What is the Difference Between Iterator and Enumeration in Java ?

Both Iterator and Enumeration are interfaces in Java to access Data Structures. The main differences between these are...

Enumeration is an older interface. Iterator is a newer interface.

Enumeration can only traverse legacy collections. Iterator can traverse both legacy as well as newer collections.

Enumeration does not provide remove() method. So we cannot remove any element during traversal. Iterator provides remove() method.

Iterator is a fail-fast interface, it gives ConcurrentModificationException if any thread tries to modify an element in the collection being iterated. Enumeration is not fail-fast.

Method names in Iterator are shorter than in an Enumeration.



You May Interest

What is a Singleton Class in Java ?

Why an Object Used as Key in HashMap Should Be Immutable in Java ...

What are the Differences Between a Checked and Unchecked Exceptio ...

Java How To Find The Average Of 10 Numbers Using A While Loop

What is the Use of Jsp:useBean in JSP ?