1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
/* Create Java ArrayList From Enumeration Example This java example shows how to create an ArrayList from any Enumeration object using list method of Collections class. */ import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; import java.util.Vector; public class CreateArrayListFromEnumerationExample { public static void main(String[] args) { //create a Vector object Vector v = new Vector(); //Add elements to Vector v.add("A"); v.add("B"); v.add("D"); v.add("E"); v.add("F"); System.out.println("Vector contains : " + v); /* To create ArrayList from any Enumeration, use static ArrayList list(Enumeration e) method of Collections class. This method returns the ArrayList containing the elements returned by specified Enumeration object in order they are returned. */ //Get Enumeration over Vector Enumeration e = v.elements(); //Create ArrayList from Enumeration of Vector ArrayList aList = Collections.list(e); System.out.println("Arraylist contains : " + aList); } } /* Output would be Vector Contains : [A, B, D, E, F] Arraylist contains : [A, B, D, E, F] */ |
Add Comment