Program to Convert a Vector to List in Java

Given a Vector, the task is to Convert Vector to List in Java
Examples:
Input: Vector: [1, 2, 3, 4, 5] Output: List: [1, 2, 3, 4, 5] Input : Vector = [a, b, c, d, e, f] Output : List = [a, b, c, d, e, f]
- Using Collections.list() method
Syntax:
List list = Collections.list(vec.elements());
Approach:
- Get the Vector
 - Convert into list using Collections.list(vector.elements()) method, which returns a List of objects.
 - Print the List
 
Below is the implementation of the above approach:
// Java program to// convert vector to ListÂÂimportjava.util.*;ÂÂpublicclassGFG {   Âpublicstaticvoidmain(String[] args)   Â{       Â// Create a Vector of String elements       ÂVector<String> vec =newVector<String>();       Â// Adding values of Vector       Âvec.add("1");       Âvec.add("2");       Âvec.add("3");       Âvec.add("4");       Âvec.add("5");       Â// print Vector elements       ÂSystem.out.println("Vector: "+ vec);       Â// Convert Vector to List       ÂList<String>           Âlist = Collections.list(vec.elements());       Â// print List Elements       ÂSystem.out.println("List:"+ list);   Â}}Output:Vector: [1, 2, 3, 4, 5] List:[1, 2, 3, 4, 5]
 - Using Collection.unmodifiableList()
Syntax:
List list = Collections.unmodifiableList(vector);
Approach:
- Get the Vector
 - Convert into list using Collections.unmodifiableList(vector) method, which returns an immutable List of objects.
 - Print the List
 
Below is the implementation of the above approach:
// Java program to// convert vector to ListÂÂimportjava.util.*;ÂÂpublicclassGFG {   Âpublicstaticvoidmain(String[] args)   Â{       Â// Create a Vector of String elements       ÂVector<String> vec =newVector<String>();       Â// Adding values of Vector       Âvec.add("1");       Âvec.add("2");       Âvec.add("3");       Âvec.add("4");       Âvec.add("5");       Â// print Vector elements       ÂSystem.out.println("Vector: "+ vec);       Â// Convert Vector to List       ÂList<String>           Âlist = Collections.unmodifiableList(vec);       Â// print List Elements       ÂSystem.out.println("List:"+ list);   Â}}Output:Vector: [1, 2, 3, 4, 5] List:[1, 2, 3, 4, 5]
 - Using constructor
Syntax:
List list = new ArrayList(vector);
Approach:
- Get the Vector
 - Create a List from the Vector by passing the vector as the parameter.
 - Print the List
 
Below is the implementation of the above approach:
// Java program to// convert vector to ListÂÂimportjava.util.*;ÂÂpublicclassGFG {   Âpublicstaticvoidmain(String[] args)   Â{       Â// Create a Vector of String elements       ÂVector<String> vec =newVector<String>();       Â// Adding values of Vector       Âvec.add("1");       Âvec.add("2");       Âvec.add("3");       Âvec.add("4");       Âvec.add("5");       Â// print Vector elements       ÂSystem.out.println("Vector: "+ vec);       Â// Convert Vector to List       ÂList<String>           Âlist =newArrayList<String>(vec);       Â// print List Elements       ÂSystem.out.println("List:"+ list);   Â}}Output:Vector: [1, 2, 3, 4, 5] List:[1, 2, 3, 4, 5]
 
				
					


