How to Convert Enumeration to Arraylist – Java Example

We can convert enumeration to arraylist in java with  the help list() method of Collections.
package javaproficeincy;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;
public class EnumerationToList {
public static void main(String[] args) {
Vector<String> vt = new Vector<String>();
        vt.add(“java”);
        vt.add(“php”);
        vt.add(“array”);
        vt.add(“string”);
        vt.add(“c”);
        Enumeration<String> enm = vt.elements();
        List<String> ll = Collections.list(enm);
        System.out.println(“List elements: “+ll);
}
}
Output:
List elements: [java, php, array, string, c]
Related Posts :

26 comments

Leave a Reply

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

+ 22 = 28