List list = new Vector();
List< String> list = new Vector< String> ();
import java.util.Collections;Runtime:
import java.util.List;
import java.util.Vector;
public class VectorToList {
public static void main(String[] args) {
Vectorvec = new Vector ();
//add objects
vec.add("obj1");
vec.add("obj2");
vec.add("obj3");
System.out.println("Vector Elements:");
for(String e:vec)
System.out.println(e);
//convert Vector to List
Listlist = Collections.list(vec.elements());
//display List
System.out.println("List Items:");
for(String e:list)
System.out.println(e);
}
}
Vector Elements:If you If you want to convert Vector to an ArrayList, which is inherited from the List implementation, you can do this:
obj1
obj2
obj3
List Elements:
obj1
obj2
obj3
List newList = new ArrayList(vector);
List< String> newList = new ArrayList< String> (vector);I suggest you read the article that explains better converting a Vector to an ArrayList.
Please disable your ad blocker and refresh the window to use this website.