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.

Rabins Sharma Lamichhane

Rabins Sharma Lamichhane is senior ICT professional who talks about #it, #cloud, #servers, #software, and #innovation. Rabins is also the first initiator of Digital Nepal. Facebook: rabinsxp Instagram: rabinsxp

You may also like...

Leave a Reply

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