Ads Sponsored By Google :)

Tuesday 22 January 2013

enumeration and|vs iteratorin java|5|6|1.5 example|api|tutorial difference|between


eunmeration in java enumeration in java example enumeration example in java eunmeration in java tutorial
eunmeration in java api difference between enumeration and iterator difference between enumeration and iterator in java eunmeration in java 5 eunmeration in java example with hashtable enumeration vs iterator enumeration vs iterator in java eunmeration in java example 1.5 enumeration in java 6 tutorial difference between enumeration and list difference between enumeration and iterator java enumeration and iterator in java enumeration and iterator difference in java


Enumeration :
                
                 Enumeration is one for the predefined interface present in java.util.* package. An object of Enumeration  is always used for extracting or retrieving the data from any legacy collection frame work variable only in forward direction but not in back ward direction.

    Like Iterator  interface object, an object of Enumeration is also by default pointing before the first element of Legacy Collection Frame work variable.
  The functionality of Enumeration is more or less similar to Iterator interface. But iterator interface belongs to non-synchronized and Enumeration interface belongs to synchronized.


Difference Between Iterator and Enumeration ?

Both Iterator and Enumeration Interfaces are used for extracting the data from any object, only in forward direction. But their differ in such that Iterator belongs to Non-synchronized and Enumeration belongs to synchronized(legacy collection frame work).


     Methods in Enumeration :
        
         1)      Public boolean hasMoreElements():
                    This method is used to returns true provided Enumeration interface object having 
        more number of elements. Otherwise it returns false.

       2)      Public boolean nextElement() :
                  This method is used for obtaining next element of any Legacy collection frame work 
      variable w.r.t enumeration interface object provided method1 hasMoreElements() returns 
      true.

The Following Example Illustrate the Concept of Enumeration  Interface and it’s Method’s :

           Consider Enumeration reference en and this reference pointing before Any object like Vector, Stack etc…. v or s .

The basic use of Enumeration interface is used  to retrieve the elements in synchronize manner such that following code will illustrate it.
   
     Class ExDemo
    {
        Public static void main(String args[])
       {
        Vector v=new Vector();
         // v contains elements as10,20.3,40.53
         Enumeration en=v.elements();
       // to retrieve these elements
           While(en.hasMoreElements())
          {
            Object obj=en.nextElement();
             System.out.println(obj);
          }
       }
     }


 Data Extraction Interfaces are as follows :

     
1- D and 2-D Collection Frame work classes are 
   


        To read the values dynamically from keyboard their is a class.
                 Java.util.Scanner or Scanner class



No comments:

Post a Comment

LinkWithin