• Post Reply Bookmark Topic Watch Topic
  • New Topic

vector class  RSS feed

 
Ranjeet Kr Rai
Greenhorn
Posts: 12
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Vector class how capacity() is different than size() and what about
 
Stephan van Hulst
Saloon Keeper
Posts: 7821
142
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The size of a vector is how many items are currently held by it. The capacity is how many items it can hold in total, before it needs more memory.
 
Anooj Narvekar
Greenhorn
Posts: 10
IntelliJ IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya.. and

Vector(int initCapacity, int capIncrement )

is to initialize vector with a initial capacity, and capIncrement parameter mentions by how much should the current capacity be increased upon filling the vector.

Think of vector as an Array. Instead of increasing the size of vector at every insert into the vector, providing init capacity makes lot of sense as you will avoid un-necessary array copying and re-inserting
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using Vector in the first place, rather than ArrayList?
A lot of people think it was a mistake to permit users to set a size increment like that. So ArrayList doesn't have such a constructor.
 
Sunny Bhandari
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also read about this in more detail for java source code for that constructor...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!