File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 203

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: 4635

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.

The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
I agree. Here's the link:
subject: Vector Over ArrayList in term of Capacity..!!
jQuery in Action, 3rd edition