Java Collections emptyEnumeration() Method with Examples
Last Updated :
27 Apr, 2023
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
import java.util.*;
public class GFG {
public static void main(String[] args)
{
Enumeration<String> obj
= Collections.emptyEnumeration();
System.out.println(obj.hasMoreElements());
}
}
|
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
import java.util.*;
public class GFG {
public static void main(String[] args)
{
List<String> data = new ArrayList<String>();
data.add( "java" );
data.add( "python" );
data.add( "php" );
data.add( "html/css" );
Enumeration<String> enm
= Collections.emptyEnumeration();
while (enm.hasMoreElements()) {
System.out.println(enm.nextElement());
}
System.out.println( "Empty" );
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...