Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Vector Over ArrayList in term of Capacity..!!

 
Saral Saxena
Ranch Hand
Posts: 203
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
As I was going through differences between vector<T> & ArrayList<T> in that section I had gone through that You can specify how a Vector<T> object should increase its capacity when it is necessary whereas with an ArrayList<T> you cannot. You can have some control over how an ArrayList<T> increases in capacity by using its ensureCapacity() method that sets a given capacity and another thing You can discover the current capacity of a Vector<T> by calling its capacity() method. You have no way to know the current capacity of an ArrayList<T> unless you have set its capacity explicitly...!! Please guys can You help me improving this with a shortr example..!!
 
Stephan van Hulst
Bartender
Pie
Posts: 5406
52
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well why would you even want to know what the capacity is in the first place? It's an implementation detail that makes the list work reasonably fast, and beyond the ensureCapacity() method not very interesting. They did well hiding this stuff from the client.

And Vector is pretty much obsolete. Just pretend it's not part of the standard API.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic