Saturday 23 June 2012

java program that describes various operation on Vector.

import java.util.*;
import java.io.*;
class VectorDemo2
{
     public static void main(String args[])
     {
    Vector<Integer> v = new Vector<Integer>();
    System.out.println("Initial size: " + v.size());
    System.out.println("Initial capacity: " + v.capacity());
   
    v.addElement(new Integer(1));
    v.addElement(new Integer(2));
    v.addElement(new Integer(3));    
    v.addElement(new Integer(4));





    System.out.println(v);
    System.out.println(v.indexOf(3));
    System.out.println(v.contains(3));
    System.out.println("Current capacity: " + v.capacity());
    v.setSize(8);
    v.set(5,6);
    System.out.println(v.get(3)+" "+v.size()+""+v);
    }   
}

No comments:

Post a Comment