Java Program for Vector

Write a Java program to implement a vector that accepts five items from the command line and store them in a vector and display the objects stored in a vector.



Source Code
import java.lang.*;
import java.io.*;
import java.util.*;

public class VectorDemo {
	
	public static void main(String args[]) {
		
		Vector list = new Vector();
		int len=args.length;
		
		for(int i=0;i<len;i++) {
			
			list.addElement(args[i]);
		}
		
		int size=list.size();
		String str[]= new String[size];
		list.copyInto(str);
		for(int i=0;i<size;i++) {
			
			System.out.println ("Element of Vector at position "+i+":"+str[i]);
		}
	}
}
Output
C:\>java VectorDemo 12 Rahul a 15.2
Element of Vector at position 0:12
Element of Vector at position 1:Rahul
Element of Vector at position 2:a
Element of Vector at position 3:15.2