Get Enumeration Over Java ArrayList
ArrayList class is a re-sizeable array that is present in java.util package. Unlike the built-in arrays, ArrayList can change their size dynamically where elements can be added and removed from an ArrayList.
In java version 1, enum was not present. With advancement to version, 1.5 enum was introduced in java which is not as same as seen in C/C++ so do the functionality differs. Enum is basically used to constrict the range for example moths, age, or be it a string (considering name of a company) which can not be changed as final values initially itself. In java version 1, enumeration was carried out by interfaces. After version 1.5 it was introduced in java as discussed so simply importing enum class makes working with enum easy simply by importing classes.
ArrayList can be of any type as shown below. The enumeration method of java.util.Collections class is used to return an enumeration over the specified collection.
- An ArrayList of integer, string, double, etc.
- ArrayList of ArrayLists, or simply an ArrayList of HashMaps.
- An ArrayList of any user-defined objects.
Syntax: For declaring an enumeration
public static Enumeration enumeration(Collection c) ;
Method Used: hasMoreElements() Method
An object that implements the Enumeration interface generates a series of elements, one at a time. hasMoreElements() method of enumeration used to tests if this enumeration contains more elements. If enumeration contains more elements than it will return true else false.
boolean hasMoreElements() ;
Parameters: This method accepts nothing.
Return value: This method returns true if and only if this enumeration object contains at least one more element to provide; false otherwise.
Perfume Clothes Sandal Jewellery Watch
Java C++ Kotlin Scala Ruby Python C#