Java – Conversion of Arrays to Vector

In this article, we will discuss how to convert Arrays into Vector using Arrays class’s utility asList() method

Conversion of Arrays into Vector :

Method signature:

1
public static List asList(Object[] oArray);

ConvertArraysIntoVector.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package in.bench.resources.java.collections;
 
import java.util.Arrays;
import java.util.Vector;
 
public class ConvertArraysIntoVector {
 
    public static void main(String[] args) {
 
        // declaration
        Integer[] intHundredArrays = {500, 200, 100, 400, 300};
        String[] strRiverArrays = {
                "Ganga",
                "Yamuna",
                "Sutlej",
                "Chenab"
        };
 
        // conversion of Integer Arrays to Vector
        Vectory<Integer> intHundredVector =
                new Vector<Integer>(Arrays.asList(intHundredArrays));
        System.out.println("Conversion of"
                + " Integer Arrays to Vector<Integer>:\n\n"
                + intHundredVector);
 
        // conversion of String Arrays to List
        Vector<Integer> strRiverVector =
                new Vector<Integer>(Arrays.asList(strRiverArrays));
        System.out.println("\n\n\nConversion of"
                + " String Arrays to Vector<Integer>:\n\n"
                + strRiverVector);
    }
}

Output:

1
2
3
4
5
6
7
Conversion of Integer Arrays to Vector<Integer>:
 
[500, 200, 100, 400, 300]
 
Conversion of String Arrays to Vector<String>:
 
[Ganga, Yamuna, Sutlej, Chenab]

Related Articles :

References :

Happy Coding !!
Happy Learning !!

Java - How to get size or length of HashSet ?
Java - Conversion of LinkedList into Vector