1.

Main difference between Iterator and Enumeration

Answer»

Main difference between Iterator and Enumeration
Below are the FOUR main difference between Iterator and Enumeration
(1)Iterator:-Iterator in java is an interface which is found in java.util package.
(1)Enumeration:-On the other hand Enumeration is an object that will creates elements but one at a time.

(2)Iterator:-Here we uses three methods to interface
(i)hasNext()
(ii)next()
(III)remove()
(2)Enumeration:-Here we uses two methods
(i)hasMoreElements()
(ii)nextElement()

(3)Iterator:-Iterators allow removing elements from the GIVEN collection during the iteration with well-defined semantics.
(3)Enumeration:-It is USED for passing through a collection, usually of unknown size.

(4)Iterator:-Iterator method NAMES have been improved.
(4)Enumeration:-Here traversing of elements can only be done once per creation.



Discussion

No Comment Found