Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-04-2007, 06:58 PM
Moderator
 
Join Date: Nov 2007
Posts: 1,637
Java Tip will become famous soon enoughJava Tip will become famous soon enough
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.

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:
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Limiting the capacity of a cell of JTable rameshraj Advanced Java 0 03-24-2008 03:20 PM
Vector help king_arthur New To Java 3 01-22-2008 08:33 PM
Initial capacity of ArrayList bugger New To Java 10 12-06-2007 01:25 PM
Vector Capacity JavaForums Java Blogs 0 12-03-2007 01:10 AM
Vector create Warren New To Java 3 11-19-2007 09:13 PM


All times are GMT +3. The time now is 09:00 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org