• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

vector class

 
Greenhorn
Posts: 12
Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Vector class how capacity() is different than size() and what about
 
Saloon Keeper
Posts: 14502
325
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 10
Mac OS X IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 76879
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also read about this in more detail for java source code for that constructor...
reply
    Bookmark Topic Watch Topic
  • New Topic