Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 368
  • Last Modified:

Enumeration vs. Iterator

In the API docs we read that we can easily read the contents of a collection with enumerations:

for (Enumeration e = v.elements() ; e.hasMoreElements() ;) {
    System.out.println(e.nextElement());
}

So, what is the advantage (or difference) of Iterators when accessing collections? (If any)

0
piou
Asked:
piou
  • 2
1 Solution
 
jimmackCommented:
From the javadoc for java.util.Iterator ;-)


Iterator takes the place of Enumeration in the Java collections framework. Iterators differ from enumerations in two ways:

# Iterators allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics.
# Method names have been improved.

0
 
jimmackCommented:
;-)  Thanx.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now