What is difference between Iterator and Enumeration?

devquora
devquora

Posted On: Jan 13, 2023

 

Both Iterator and Enumeration are used in Java to iterate over a collection of elements, but they have some important differences.

  • Iterator was introduced in JDK 1.2, while Enumeration was available from the initial version of Java.
  • An iterator is a more modern and powerful way of traversing a collection, it has more functionality than Enumeration.
  • Iterator allows the caller to remove elements from the underlying collection during the iteration with well-defined semantics, Enumeration is read-only and does not provide this functionality.
  • Iterator has a remove() method to remove the current element from the collection, Enumeration does not have this method.
  • Iterator is used in the latest collection classes like ArrayList, LinkedList,

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Core Java Interview Questions

    Explain the significance of class loaders in Bootstrap?

    In order to load the Java Classes into a virtual environment, Classloader are used. A class loader will load key classe..

    Core Java Interview Questions

    What is the difference between JDK, JRE, and JVM?

    It is important to understand the difference between JDK, JRE, and JVM in Java.JVM (Java Virtual Machine) Java..

    Core Java Interview Questions

    What are the various access specifiers in Java?

    Access specifiers in java are the keywords which define the access scope of the function. It can be used before a class..