• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regarding Vector  RSS feed

 
karthi keyan R
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Friends,
Can any one tell How the Vector class object grows or expand his size dynamically,
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

Nothing magic about it. Vector has an array member in which it keeps the element data, and a count of elements. It tries to keep the array a little larger than needed, so growing by a few elements just involves using some of that extra space and incrementing the counter. When the Vector runs out of extra space, it allocates a new, larger array, and copies the old data into it.

The source code for all the JDK API classes (which, in general, is well-documented and easy to read) is part of the JDK download. Look for JAVA_HOME/src.jar to see if you've already got it installed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!