What is the difference between Enumeration And Iterator?
Enumeration
|
Iterator
|
1. It is legacy interface and introduced in 1.0 version | 1 It is non-legacy and introduced in 1.2 version |
2.Applicable only for legacy classes and it is not universal cursor | 2. 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 | 3. While iterating we can perform removal also in addition to read operation. |
4.By using elements() method we can get Enumeration object | 4. By using iterator() method we can get Iterator object |
Iterator
|
Enumerator
|
Iterator supports remove() method
|
Enumerator doesn’t supports remove()
method.
|
It is nor synchronized
|
It is synchronized
|
It supports ArrayList, vector,
hashmap, hashtable
|
It doesn’t supports Arraylist, and
hashmap.
|
It doesn’t supports legacy methods
|
It supports legacy methods like
hasMoreElements(),nextElements();
|