Programming Tutorials

Vector in Java - Sample Program

By: Paawan Chaudhary in Java Tutorials on 2012-09-19  

This java program implements 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]);
		}
	}
}





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Java )

Latest Articles (in Java)