Convert ArrayList to Enumeration in Java

In this example, We will show you simple example program about, How to convert ArrayList to Enumeration in Java.

Example Program

package com.dineshkrish;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
/**
* 
* @author Dinesh Krishnan
*
*/
public class CoversionExample {
public static void main(String[] args) {
// defining list object
List<String> list = new ArrayList<String>();
// adding the elements
list.add("One");
list.add("Two");
list.add("Three");
list.add("Four");
list.add("Five");
// converting list to enumeration
Enumeration<String> enumObj = Collections.enumeration(list);
// iterating enumeration object
while(enumObj.hasMoreElements()) {
System.out.println(enumObj.nextElement());
}
}
}

References

1. Java List Interface
2. Java ArrayList Class
3. Java Collections Class
4. Java Collections.enumeration() Method
5. Java Enumeration Interface

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *