I found a good article describe the differences in a good description with summary:
Iterator , ListIterator and Enumeration interfaces are mainly used to iterate collection classes .
Enumeration :
Enumeration iterates Vector and Hashtable .
Reverse iteration is not possible with enumeration.
It cannot add or remove elements while iteration .
Iterator :
Iterator iterates the implementations of List , Set .
Reverse iteration is not possible with Iterator .
Iterator cannot add elements , but it can remove elements while iteration .
ListIterator :
ListIterator iterates List implementations (like ArrayList , LinkedList etc).
Both forward and backward iterations are possible with ListIterator .
Both elements addition and deletion can possible with ListIterator .
http://java2db.com/java-util/difference-between-iterator-listiterator-and-enumeration-in-java
Iterator , ListIterator and Enumeration interfaces are mainly used to iterate collection classes .
Enumeration :
Enumeration iterates Vector and Hashtable .
Reverse iteration is not possible with enumeration.
It cannot add or remove elements while iteration .
Iterator :
Iterator iterates the implementations of List , Set .
Reverse iteration is not possible with Iterator .
Iterator cannot add elements , but it can remove elements while iteration .
ListIterator :
ListIterator iterates List implementations (like ArrayList , LinkedList etc).
Both forward and backward iterations are possible with ListIterator .
Both elements addition and deletion can possible with ListIterator .
Syntax for Iterator ListIterator and Enumeration :
Iterator <Iterator variable name>= <set/List variable> . iterator(); while(<Iterator variable name>.hasNext()) { <Iterator variable name> .next(); } |
ListIterator <ListIterator variable name>=<list variable>.listIterstor(); while (<ListIterator variable name>.hasNext() ){ <ListIterator variable name>.next(); } |
Enumeration <Enumeration variable name>=<Vector / Hashtable variable>.elements(); while(<Enumeration variable name>.hasMoreElements()) { <Enumeration variable name>.nextElement(); } |
http://java2db.com/java-util/difference-between-iterator-listiterator-and-enumeration-in-java
No comments:
Post a Comment