Tell me the differences between enumeration and iteration?Which can use where in realtime?

Showing Answers 1 - 28 of 28 Answers

Navdeep

  • Nov 21st, 2005
 

Enumeration deals with objects while iteration deals with values only. Enumeration is used when we use vector, hashtable, etc while iteration are used in while loop, for loop etc

  Was this answer useful?  Yes

praveen

  • Nov 27th, 2005
 

Hi !,

     Both will help you to travel into collection bag, But Enumeration is a leagsy classes and it comes with java1.1, Iterater they have introduced in Collection framework.

In enumeration we can modify the collection objects but throw Iterator it is possible.

  Was this answer useful?  Yes

x

  • Dec 9th, 2005
 

Enumerator and Iterator are almost same.But in Iterator there is one extra method called "remove".and iterator is part of the new collection class.Java API says to use more of iterator than Enumerator which is kind of old class.

  Was this answer useful?  Yes

viji

  • Dec 14th, 2005
 

Enumeration and Iterator both are interfaces present in util package. Enumeration is a legacy interface which does not come under the collection framework, wheras Iterator is an interface present in the collection framework. All the legacy classes like Stack, Vector , Hashtable, Properties can use Enumeration for enumerating the elements from the collection. The classes under the collection framework like ArrayList, LinkedList, HashSet ,Tree Set etc can use the Iterator interface

  Was this answer useful?  Yes

gursharn

  • Mar 27th, 2006
 

hi!!!

  Enumeration does not have remove method but iteration has.......

  Was this answer useful?  Yes

Mahantesh V Kabadagi

  • Jul 13th, 2006
 

Both are used to travel objects one by one, But Enumeration is a leagsy classes and it comes with java1.1, Iterater they have introduced in Collection framework.

Enumeration can be used for Collection objects as well as Iterator can be used for legacy classes.

Enumeration acts as Read-only interface, because it has the methods only to travels and fetch the objects, where as using Iterator we can manipulate the objects also like adding and removing the objects.

So Enumeration is used when ever we want to make Collection objects as Read-only.

  Was this answer useful?  Yes

Chandrakant

  • Oct 4th, 2006
 

 

Both have almost same functionality but Iterator has little bit extra added value in it......

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.

  Was this answer useful?  Yes

Enumeration - In enumeration there is no method to remove the object from the collection, and very difficult to remember the enumeration methods.

Iteration - In iteration we have remove method and also we can easily remember the methods.

  Was this answer useful?  Yes

In Enumeration we usly fetch the data only ie read only while Iteration can done all the manipulations like read, update and insert and remove also

When the requirment like only want to show the values then go for Enumeration and when we want to change the values then we go for Iteration

  Was this answer useful?  Yes

masthan02

  • Sep 13th, 2008
 

Enumeration and Iterator are the interface available in java.util package. Enumeration contains 2 methods namely hasMoreElements() & nextElement().

Iterator contains three methods namely hasNext(), next(),remove().
Using remove() we can also delete the objects but Enumeration interface does not support this feature.

chandaka

  • Sep 22nd, 2009
 

The functionality of this interface is duplicated by the Iterator interface. In addition, Iterator adds an optional remove operation, and has shorter method names. New implementations should consider using Iterator in preference to Enumeration.

  Was this answer useful?  Yes

javabuddy

  • Jan 10th, 2011
 

Between two Enumeration is older and its there from jdk 1.0 while iterator was introduced later.

The functionality of Enumeration interface is duplicated by the Iterator interface.
Iterator has a remove() method while Enumeration doesn't. Enumeration acts as Read-only interface, because it has the methods only to traverse and fetch the objects, where as using Iterator we can manipulate the objects also like adding and removing the objects.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions