3:44 pm - Friday December 11, 1131

Vector Example Program for capacity()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
@AUTHOR:Candid java.com
@DESCRIPTION:Program for print the capacity of the vector
*/

import java.util.Vector;
public class Capacity
{
public static void main(String[] args)
{
Vector v1=new Vector();
Vector v2=new Vector(4);
Vector v3=new Vector(2,2);
v1.add("One");
v1.add("Two");
v1.add("Three");
v1.add("Four");
System.out.println("Capacity of v1 " + v1.capacity());
System.out.println("Capacity of v2 " + v2.capacity());
System.out.println("Capacity of v3 " + v3.capacity());
v2.add("A");
v2.add("B");
v2.add("G");
v2.add("C");
v2.add("D");;
System.out.println("Updated capacity of v2 " + v2.capacity());
v3.addElement("1");
v3.addElement("2");
v3.addElement("3");
System.out.println("Updated capacity of v3 " + v3.capacity());
}
}

Output:

size of the vector is:0
Capacity of V1=10
Capacity of V2=4
Capacity of V3=2
Updated Capacity of V2 8
Updated Capacity of V3 4

Filed in: Z-A All Java Codes

Comments are closed.