Basic example using Vector Class in Java


Here is the simple program for printing basic example using vector class in Java.

Source Code

import java.io.*;
import java.util.*;
class vect
{
  public static void main(String args[])
  {
   Vector list =new Vector();
   int i;
   int n=args.length;
   System.out.print("\nLength : "+n);
   for(i=0;i<n;i++)
   {	
    list.addElement(args[i]);
   }
   System.out.print("\nEND_______________________-");
   for(i=0;i<n;i++)
   {
    System.out.print("\nList["+i+"]: "+list.elementAt(i));
   }
   list.insertElementAt("Computer",1);
   for(i=0;i<=n;i++)
   {
    System.out.print("\nList["+i+"]: "+list.elementAt(i));
   }
   //int size=list.size();
   //System.out.print("\nSize : "+size);
   //String name[]=new String[size];
   //list.copyInto(name);
   //for(i=0;i<=n;i++)
   //{
   //	System.out.print("\nName["+i+"] : "+name[i]);
   //}
  }	
}
/*
list.addElement(item);
list.elementAt(2);
list.size();
list.removeElement(item);
list.removeElementAt(n);
list.removeElements();
//list.copyInto(array);
list.insertElementAt(item,n);
*/
To download raw file Click Here

Output

Tutor
Length : 1
END_______________________-
List[0]: Tutor
List[0]: Tutor
List[1]: Computer


Learn All in Tamil © Designed & Developed By Tutor Joes