

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to convert a Vector to List in Java
Let’s say the following is our vector with values −
Vector<String> v = new Vector<String>(); v.add("20"); v.add("40"); v.add("60"); v.add("80"); v.add("100");
Now, convert the above Vector to List −
List<String>myList = new ArrayList<String>(v);
Example
Following is the program to convert a Vector to List in Java −
import java.util.*; public class Demo { public static void main(String[] args) { Vector<String> v = new Vector<String>(); v.add("20"); v.add("40"); v.add("60"); v.add("80"); v.add("100"); v.add("120"); v.add("140"); v.add("160"); v.add("200"); System.out.println("Vector elements = " + v); List<String>myList = new ArrayList<String>(v); System.out.println("List (Vector to List) = " + myList); } }
Output
Vector elements = [20, 40, 60, 80, 100, 120, 140, 160, 200] List (Vector to List) = [20, 40, 60, 80, 100, 120, 140, 160, 200]
Example
Let us see another example −
import java.util.*; public class Demo { public static void main(String[] args) { Vector<String> v = new Vector<String>(); v.add("20"); v.add("40"); v.add("60"); v.add("80"); v.add("100"); v.add("120"); v.add("140"); v.add("160"); v.add("200"); System.out.println("Vector elements = " + v); List<String>myList = Collections.list(v.elements()); System.out.println("List (Vector to List) = " + myList); } }
Output
Vector elements = [20, 40, 60, 80, 100, 120, 140, 160, 200] List (Vector to List) = [20, 40, 60, 80, 100, 120, 140, 160, 200]
- Related Questions & Answers
- Java Program to convert a list to a read-only list
- Java Program to convert a List to a Set
- How to convert a named vector to a list in R?
- Java program to convert a list to an array
- Java program to convert an array to a list
- Convert a Vector to an array in Java
- Java Program to convert Stream to List
- Program to convert Array to List in Java
- Program to convert List to Stream in Java
- Program to convert Set to List in Java
- Java Program to convert Properties list into a Map
- How to convert an Array to a List in Java Program?
- Program to convert List of Integer to List of String in Java
- Program to convert List of String to List of Integer in Java
- Java program to convert the contents of a Map to list
Advertisements