Results 1 to 1 of 1

Thread: Vector capacity

  1. #1
    Java Tip's Avatar
    Java Tip is offline Moderator
    Join Date
    Nov 2007
    Posts
    1,694
    Blog Entries
    430
    Rep Power
    10

    Default 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());
    Output:
    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 07:04 PM.

Similar Threads

  1. Vector create
    By Warren in forum New To Java
    Replies: 4
    Last Post: 03-02-2010, 03:42 AM
  2. Initial capacity of ArrayList
    By bugger in forum New To Java
    Replies: 12
    Last Post: 12-30-2009, 09:16 AM
  3. Limiting the capacity of a cell of JTable
    By rameshraj in forum Advanced Java
    Replies: 0
    Last Post: 03-24-2008, 03:20 PM
  4. Vector help
    By king_arthur in forum New To Java
    Replies: 3
    Last Post: 01-22-2008, 08:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •