Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
How to use the asList() method of the Arrays class to create a Vector object
A Vector can be created from an Array using the java.util.Arrays.asList() method.
A program that demonstrates this is given as follows:
Example
import java.util.Arrays;
import java.util.Vector;
public class Demo {
public static void main(String args[]) {
Integer[] arr = { 3, 1, 9, 6, 4, 8, 7 };
Vector vec = new Vector(Arrays.asList(arr));
System.out.println("The Vector elements are: " + vec);
}
}
Output
The Vector elements are: [3, 1, 9, 6, 4, 8, 7]
Now let us understand the above program.
The Integer Array arr[] is defined. Then a Vector is created using the Arrays.asList() method. Then the Vector elements are displayed. A code snippet which demonstrates this is as follows:
Integer[] arr = {3, 1, 9, 6, 4, 8, 7};
Vector<Integer> vec = new Vector(Arrays.asList(arr));
System.out.println("The Vector elements are: " + vec); Advertisements
