Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

what is difference between an iterator and Enumeration

  Asked By: Ibthaj    Date: Aug 14    Category: Java    Views: 1577
  

what is difference between an iterator and Enumeration

Share: 

 

6 Answers Found

 
Answer #1    Answered By: Nicolas Costa     Answered On: Aug 14

iterator is a repeat. enumeration is a value that replaces a number.
such as ENUM in c.

 
Answer #2    Answered By: Djoser Massri     Answered On: Aug 14

a.. Iterators and enumeration are both used to traverse through any
collection.
Their job is to move through a sequence of objects (collection) and
select each object in that sequence without the client programmer knowing or
caring about the underlying structure of that sequence.

b.. The iterators provide to remove an element from the sequence
byt enumeration does not allow removal of elements from the sequence

 
Answer #3    Answered By: Sherrie Thomas     Answered On: Aug 14

i want to use JTable with a select query, i am new
to Java and using JBuilder 8. i hav searched many
times for help but still confuse how to do, plz help
me or giv from url where i can understand easily
JTable

 
Answer #4    Answered By: Anselma Schmidt     Answered On: Aug 14

Google for JTable Tutorial. This will give you a link to the tutorial
on Sun's Java site (I just did this search and it was the first find).
There are several good examples in this tutorial, including extensive
how-tos.

 
Answer #5    Answered By: Dang Tran     Answered On: Aug 14

The designers of Java decided that all objects would be part of the same
object tree, so they chose Object as the base class for everything.
Thus, you can reference any object in the system as an Object without
knowing what it really is.

 
Answer #6    Answered By: Jamie Roberts     Answered On: Aug 14

An iterator  is considered fail-fast if it throws a
ConcurrentModificationException under either of the following two conditions:
In multithreaded processing: if one thread is trying to modify a Collection
while another thread is iterating over it.
In single-threaded or in multithreaded processing: if after the creation of the
Iterator, the container is modified at any time by any method other than the
Iterator's own remove or add methods.
Note in particular what is implied by the second condition: After we create a
container's iterator, during a loop that iterates over the container we must
only use the remove (and when applicable add) methods defined for the iterator
and that we must NOT use the same methods defined for the container itself. To
illustrate this point, suppose we declare and initialize a List in the following
manner
List list = new ArrayList();
list.add("Peter");
list.add("Paul");
list.add("Mary");

Let's say we wish to iterate over this list. We'd need to declare a ListIterator
as follows:
ListIterator iter = list.listIterator();

Having created this iterator, we could now set up a loop like:
while ( iter1.hasNext() ) {
String str = iter1.next();
// do something with str
}

Because iter is fail-fast, we are not allowed to invoke List's add or remove
methods inside the loop. Inside the loop, we are only allowed to use
ListIterator's add and remove methods. This makes sense because it is the
Iterator object that knows where it is in a List as the List is being scanned.
The List object itself would have no idea of that.
The Iterators supported by all the work-horse container classes, such as
ArrayList, LinkedList, TreeSet, and HashSet, are fail-fast. The Iterator type
retrofitted to the older container class Vector is also fail-fast. For
associative containers, such as HashMap and the older HashTable, the Iterator
type for the Collections corresponding to either the keys or the values or the
<key, value> pairs are fail-fast with respect to the container itself. That
means that even if you are iterating over, say, just the keys of the container,
any illegal concurrent modifications to the underlying container would be
detected.
One final note regarding iterators versus enumerations: It is also possible to
use an Enumeration object returned by the elements() method for iterating over
the older container types such as Vector. However, Enumerations do not provide a
fail-fast method. On the other hand, the more modern Iterator returned by a
Vector's iterator() and listIterator() methods are fail-fast. Hence, iterators
are recommended over enumerations for iterating over the elements of the older
container types.

 
Didn't find what you were looking for? Find more on what is difference between an iterator and Enumeration Or get search suggestion and latest updates.