-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathEnumeration Vs Iterator
18 lines (16 loc) · 1.17 KB
/
Enumeration Vs Iterator
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Both Enumeration and Iterator are interfaces in Java.
Both are used to store the elements of a data structure in Java
The functionality of Enumeration and the Iterator have minor difference. You can get remove()
from Iterator to remove an element, while Enumeration does not have remove()
method. Using Enumeration you can only traverse and fetch the objects, where as using
Iterator we can also add and remove the objects. So Iterator can be useful if you want
to manipulate the list and Enumeration is for read-only access.
public interface Iterator<E>
An iterator over a collection. Iterator takes the place of Enumeration in the Java Collections Framework.
Iterators differ from enumerations in two ways:
a) Iterators allow the caller to remove elements from the underlying collection during the iteration with
well-defined semantics.
b) Method names have been improved.
The Iterator interface is a member of the Java Collections Framework whereas the Enumeration interface is not.
Please see Enumeration Interface Java Docs -> http://docs.oracle.com/javase/6/docs/api/java/util/Enumeration.html
Iterator Interface Java Docs -> http://docs.oracle.com/javase/7/docs/api/java/util/Iterator.html