This week's book giveaway is in the Agile forum.
We're giving away four copies of The Software Craftsman and have Sandro Mancuso on-line!
See this thread for details.
The moose likes Java in General and the fly likes Vector Over ArrayList in term of Capacity..!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Vector Over ArrayList in term of Capacity..!!" Watch "Vector Over ArrayList in term of Capacity..!!" New topic

Vector Over ArrayList in term of Capacity..!!

Saral Saxena
Ranch Hand

Joined: Apr 22, 2011
Posts: 202

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

Joined: Sep 20, 2010
Posts: 3679

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.
Have you tried LearnNowOnline?
subject: Vector Over ArrayList in term of Capacity..!!