MY mENU


Saturday 16 March 2013

Enumeration in Java


Java.util.Enumeration:
Enumeration is one of the predefined Interface present in Java.util.* package. An object of Enumeration Interface object is used for extracting or retrieving data from any legacy collection framework variable only in forward direction. When we create on enumeration, which is by default pointing just before the first element at any legacy collection frameworks.
The functionality of Enumeration (Synchronized) is more or less Iterator Interface (Non-Synchronized)
Methods:
 Public boolean hasMoreElements(): it returns true provided enumeration Interface object is having more number of elements  in legacy collection framework variable otherwise it returns false.
Public object nextElement ():  is used for uptaining next element of any legacy collection framework variable provided Public boolean hasMoreElements() must returns true.
Syntax:
 While(en.hasMoreElements()){
Object obj=en.nextElement();
System.out.println(obj);
}