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:

public static List asList(Object[] oArray);

ConvertArraysIntoVector.java

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
		Vector<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<String> strRiverVector = 
				new Vector<String>(Arrays.asList(strRiverArrays));
		System.out.println("\n\n\nConversion of"
				+ " String Arrays to Vector<String>:\n\n" 
				+ strRiverVector);
	}
}

Output:

Conversion of Integer Arrays to Vector<Integer>:

[500, 200, 100, 400, 300]



Conversion of String Arrays to Vector<String>:

[Ganga, Yamuna, Sutlej, Chenab]

 

References:

 

Happy Coding !!
Happy Learning !!

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