- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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