Solved

Enumeration vs. Iterator

Posted on 2003-11-13
2
330 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now