Java Collections - emptyEnumeration() Method
The java.util.Collections.emptyEnumeration() method returns an enumeration that has no elements. More precisely:
- hasMoreElements always returns false.
- nextElement always throws NoSuchElementException.
Syntax
public static <T> Enumeration<T> emptyEnumeration()
Here, T is the type of element, if there were any, in the enumeration.
Parameters
No parameter is required.
Return Value
Returns an empty enumeration.
Exception
NA.
Example:
In the example below, the java.util.Collections.emptyEnumeration() method is used to create an empty enumeration.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating an empty Enumeration Enumeration<Integer> MyEnum = Collections.emptyEnumeration(); //print the content of the Enumeration while(MyEnum.hasMoreElements()) { System.out.println(MyEnum.nextElement()); } System.out.println("MyEnum is empty."); } }
The output of the above code will be:
MyEnum is empty.
❮ Java.util - Collections