Results 1 to 1 of 1
Thread: Vector capacity
-
Vector capacity
Vector class provides 3 constructors which can be used according to the needs. Following example will help you understand how the size of Vector grows.
Java Code:// constructor without any argument -- default size is 10 Vector v1 = new Vector(); // constructor with 1 argument -- size doubles as entries increases Vector v2 = new Vector(4); // constructor with 2 argument -- size increases according to the 2 int argument Vector v3 = new Vector(2,2); 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.addElement("Australia"); v2.addElement("Brazil"); v2.addElement("Germany"); v2.addElement("France"); v2.addElement("Itlay");; System.out.println("Updated capacity of v2 " + v2.capacity()); v3.addElement("Australia"); v3.addElement("Brazil"); v3.addElement("Germany"); System.out.println("Updated capacity of v3 " + v3.capacity());
Java Code:Capacity of v1 10 Capacity of v2 4 Capacity of v3 2 Updated capacity of v2 8 Updated capacity of v3 4
Last edited by Java Tip; 11-04-2007 at 06:04 PM.
Similar Threads
-
Vector create
By Warren in forum New To JavaReplies: 4Last Post: 03-02-2010, 02:42 AM -
Initial capacity of ArrayList
By bugger in forum New To JavaReplies: 12Last Post: 12-30-2009, 08:16 AM -
Limiting the capacity of a cell of JTable
By rameshraj in forum Advanced JavaReplies: 0Last Post: 03-24-2008, 02:20 PM -
Vector help
By king_arthur in forum New To JavaReplies: 3Last Post: 01-22-2008, 07:33 PM
Bookmarks