What is difference between Enumeration and Iterator?
|
Enumeration |
Iterator |
1) |
It is legacy interface and introduced in 1.0 version. |
It is non-legacy and introduced in 1.2 version. |
2) |
Applicable only for legacy classes and it is not universal
cursor. |
Applicable for any Collection implemented class object. |
3) |
While iterating the elements we are not allowed to remove
the objects just we can perform only read operation. |
While iterating we can perform removal also in addition
to read operation. |
4) |
By using elements() method we can get Enumeration object. |
By using iterator() method we can get Iterator object. |
What are limitations of Enumeration?
-
While iterating the elements we are not allowed to perform
removal operation.
-
It is applicable only for legacy classes and it is not a
universal cursor.
-
It can retrieve the elements only in forward direction.
What is difference between enum and Enumeration?
An enum can be used to define a group of named constants.
It has introduced in 1.5 version
Ex
Class Beer{
KO,KF,RC,FO
}
Enumeration is cursor to retrieve Objects one by one from
Collection objects.
What is difference between Iterator and ListIterator?
-
ListIterator is the child interface of the Iterator
-
Iterator is the single direction cursor where as ListIterator
is bidirectional cursor.
-
While iterating the elements by Iterator we can perform only
read and remove operations. But by using ListIterator we can perform read,removal,
replace and addition of new objects also.
-
Iterator is applicable for every Collecton implemented class
object but ListIterator is applicable only for List implemented class
objects.
-
Iterator can be get by using iterator() of Collection interface
where as ListIterator can be get by using listIterator() method of List
interface
-
both are introduced in 1.2 version
What is relation between ListIterator and Iterator?
ListIterator is child interface of Iterator
|