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.

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.

 

import java.lang.*;
import java.io.*;
import java.util.*;
class q8Vector
{
	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]);
		}
	}
}

Important Note:  My java.util.* package is not working so not sure whether this above program is correct or not.

Leave a Reply

Your email address will not be published. Required fields are marked *