Solved

Enumeration vs. Iterator

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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 learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

746 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

12 Experts available now in Live!

Get 1:1 Help Now