Java Collections emptyEnumeration() Method with Examples

The emptyEnumeration() method of Java Collections is used to get the empty enumeration that contains no elements in Java.
Syntax:
public static <T> Enumeration<T> emptyEnumeration()
Parameters: This method has no parameters.
Return Type: This method will return an empty enumeration.
Exceptions: This method will not arise any exceptions.
Example 1: Java program to check whether the enumeration has more elements or not. So we are using the hasMoreElements() method. This will return a boolean value. If the enumeration contains elements, it will return true, otherwise false.
Syntax:
object.hasMoreElements()
where object is an enumeration object
Java
// Java program to illustrate the// Collections emptyEnumeration()// Methodimport java.util.*;public class GFG { // main method public static void main(String[] args) { // create an empty enumeration Enumeration<String> obj = Collections.emptyEnumeration(); // check more elements or not System.out.println(obj.hasMoreElements()); }} |
false
Example 2: In this example, we are going to get the next element of the empty enumeration using nextElement().
Syntax:
object.nextElement()
where object is an enumeration object
Java
// Java program to illustrate the// Collections emptyEnumeration()// Methodimport java.util.*;public class GFG { // main method public static void main(String[] args) { // create an array list List<String> data = new ArrayList<String>(); // add elements to the list data.add("java"); data.add("python"); data.add("php"); data.add("html/css"); // create enumeration object Enumeration<String> enm = Collections.emptyEnumeration(); // get the elements while (enm.hasMoreElements()) { System.out.println(enm.nextElement()); } // display System.out.println("Empty"); }} |
Empty



