The methods declared by Enumeration

Already you See that... Enumeration on my recently post.... we have saw that about enumeration is java data structure and about it..
Now we see that about Method declared by Enumeration




The Enumeration interface defines the methods by which you can enumerate (obtain one at a time) the elements in a collection of objects.
This legacy interface has been superceded by Iterator. Although not deprecated, Enumeration is considered obsolete for new code. However, it is used by several methods defined by the legacy classes such as Vector and Properties, is used by several other API classes, and is currently in widespread use in application code.

The methods declared by Enumeration are summarized in the following table:


Methods with Description:

1)boolean hasMoreElements( ):

When implemented, it must return true while there are still more elements to extract, and false when all the elements have been enumerated.

2)Object nextElement( ):

This returns the next object in the enumeration as a generic Object reference.

It's Just simple java program about enumeration structure...

import java.util.Vector;
import java.util.Enumeration;

public class EnumerationTester {

   public static void main(String args[]) {
      Enumeration days;
      Vector dayNames = new Vector();
      dayNames.add("Sunday");
      dayNames.add("Monday");
      dayNames.add("Tuesday");
      dayNames.add("Wednesday");
      dayNames.add("Thursday");
      dayNames.add("Friday");
      dayNames.add("Saturday");
      days = dayNames.elements();
      while (days.hasMoreElements()){
         System.out.println(days.nextElement()); 
      }
   }
}

Comments