The Java Collections emptyEnumeration() method is used to get the empty enumeration. Enumeration is empty and its hasMoreElements method always returns false.
DeclarationFollowing is the declaration for Java Collections emptyEnumeration() method.
public static final <T> Enumeration<T> emptyEnumeration()Parameters
NA
Return ValueNA
ExceptionNA
Getting Empty Enumeration of Integers ExampleThe following example shows the usage of Java Collection emptyEnumeration() method to get an empty enumeration of Integers. We've created an empty enumeration using emptyEnumeration() method and then checked if enumeration has elements or not.
package com.tutorialspoint; import java.util.Collections; import java.util.Enumeration; public class CollectionsDemo { public static void main(String args[]) { // create an empty list Enumeration<Integer> emptyEnumeration = Collections.emptyEnumeration(); System.out.println("Created empty enumeration, it has elements: "+emptyEnumeration.hasMoreElements()); } }Output
Let us compile and run the above program, this will produce the following result.
Created empty enumeration, it has elements: falseGetting Empty Enumeration of Strings Example
The following example shows the usage of Java Collection emptyEnumeration() method to get an empty enumeration of Strings. We've created an empty enumeration using emptyEnumeration() method and then checked if enumeration has elements or not.
package com.tutorialspoint; import java.util.Collections; import java.util.Enumeration; public class CollectionsDemo { public static void main(String args[]) { // create an empty list Enumeration<String> emptyEnumeration = Collections.emptyEnumeration(); System.out.println("Created empty enumeration, it has elements: "+emptyEnumeration.hasMoreElements()); } }Output
Let us compile and run the above program, this will produce the following result.
Created empty enumeration, it has elements: falseGetting Empty Enumeration of Objects Example
The following example shows the usage of Java Collection emptyEnumeration() method to get an empty enumeration of Student objects. We've created an empty enumeration using emptyEnumeration() method and then checked if enumeration has elements or not.
package com.tutorialspoint; import java.util.Collections; import java.util.Enumeration; public class CollectionsDemo { public static void main(String args[]) { // create an empty list Enumeration<Student> emptyEnumeration = Collections.emptyEnumeration(); System.out.println("Created empty enumeration, it has elements: "+emptyEnumeration.hasMoreElements()); } } class Student { int rollNo; String name; Student(int rollNo, String name){ this.rollNo = rollNo; this.name = name; } @Override public String toString() { return "[ " + this.rollNo + ", " + this.name + " ]"; } }Output
Let us compile and run the above program, this will produce the following result.
Created empty enumeration, it has elements: false
java_util_collections.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4