All About Interface Enumeration in Java

An object that implements the Enumeration interface generates a series of elements,one at a time. Successive calls to the nextElement() method which returns the successive elements of the Enumeration series, methods are provided to enumerate through the elements of a vector, the key of a hashtable and the values in a hashtable.Enumerations are also used to specify th einput streams from a sequenceInputStream.

Exp:
for printing all elements of a vector myVec:

for(Enumeration e=myVec.elements();e.hasMoreElement())
{
System.out.println(e.nextElement());
}
 
The interface looks below:

public interface java.util.Enumeration{
//methods:
public abstruct boolean hasMoreElements();
//returns true if the enumeration contains more elements and returns false if the enumeration contains no elements
public abstruct Object nextElement()
//returns the next element of this enumeration. It can throw NoSuchElementException if there is not element present.

}

All About Interface Enumeration in Java All About Interface Enumeration in Java Reviewed by Animesh Chatterjee on September 14, 2018 Rating: 5

No comments:

Powered by Blogger.