Friday, October 17, 2025
HomeLanguagesJavaJava Collections emptyEnumeration()​ Method with Examples

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()​
// Method
import 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());
    }
}


Output

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()​
// Method
import 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");
    }
}


Output

Empty
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS