Solved

Enumeration vs. Iterator

Posted on 2003-11-13
2
349 Views
Last Modified: 2010-05-18
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
Comment
Question by:piou
  • 2
2 Comments
 
LVL 15

Accepted Solution

by:
jimmack earned 75 total points
ID: 9739321
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
 
LVL 15

Expert Comment

by:jimmack
ID: 9748662
;-)  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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
windows explorer path to command prompt 5 54
mysql jsp example issue 32 48
ejb message driven bean mdb creation steps 2 20
Running JavaFX on the Raspberry Pi 27 39
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question