Sunday, February 22, 2009

sample code to demonistrate vector class




package collection;
import java.util.*;
class VectorDemo
{
public static void main(String arg[])
{
Vector v=new Vector();
v.addElement("a");
for(int i=0;i<10;i++)
{
v.addElement(new Integer(i));
}
System.out.println(v);
System.out.println(v.capacity()); // 10
v.add("b");
System.out.println(v.capacity()); // 20
}
}

output:
[a, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
20
20



0 comments:

Post a Comment