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:
- https://docs.oracle.com/javase/tutorial/collections/intro/
- https://docs.oracle.com/javase/tutorial/collections/interfaces/collection.html
- https://docs.oracle.com/javase/7/docs/api/java/util/Collection.html
- https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html
- https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
- https://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Array.html
- https://docs.oracle.com/javase/specs/jls/se7/html/jls-10.html
- https://docs.oracle.com/javase/7/docs/api/java/util/Vector.html
- https://docs.oracle.com/javase/8/docs/api/java/util/Vector.html
Happy Coding !!
Happy Learning !!