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 :

Notice: compact(): Undefined variable: limits in /home/javaprof/public_html/wp-includes/class-wp-comment-query.php on line 853

Notice: compact(): Undefined variable: groupby in /home/javaprof/public_html/wp-includes/class-wp-comment-query.php on line 853

Notice: compact(): Undefined variable: limits in /home/javaprof/public_html/wp-includes/class-wp-comment-query.php on line 853

Notice: compact(): Undefined variable: groupby in /home/javaprof/public_html/wp-includes/class-wp-comment-query.php on line 853

24 comments

Leave a Reply to Unknown Cancel reply

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

54 − = 50