Syntax error Difference Between Iterator and Enumeration Interface in Java

Difference Between Iterator and Enumeration Interface in Java



In this post, we will understand the difference between iterator and enumeration interfaces in Java.

Iterator

  • It is a universal cursor.

  • It can be applied to all collection of classes.

  • It contains the ‘remove’ method.

  • It is not a legacy interface.

  • It can be used to traverse over HashMap, LinkedList, ArrayList, HashSet, TreeMap, and TreeSet .

  • It can perform modifications to perform operations on the collection while traversing through it.

Enumeration

  • It is not a universal cursor.

  • It is applied only to legacy classes.

  • It doesn’t contain the ‘remove’ method.

  • It is a legacy interface.

  • This interface acts like a read-only interface.

  • Hence, no modifications can be performed on a collection while traversing over the elements in a Collection.

  • It can be used to traverse over Vectors, and Hashtable.

Updated on: 2021-03-24T12:34:07+05:30

570 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements