To clarify just a bit. ArrayList is not synchronized. So if you have several users adding or removing data from the same ArrayList but from different threads you could have some trouble. I believe List is synchronized.
For a good Prime, call:<br />29819592777931214269172453467810429868925511217482600306406141434158089
I believe List is synchronized. Probably you meant "I believe Vector is synchronized." List is an interface - some implementations are synchronized, and some are not. If you need synchronization, you still don't need Vector - put in the synchronized blocks yourself, or use Collections.synchronizedList() to get a synchronized view. As far as theo original question, ignoring synchronization: if you don't have to resize the array/collection ever, then arrays are fastest and consume the least resources. If you do need to resize, you probably want ArrayList or LinkedList. If objects are only added or removed at the end of the list, use ArrayList; if they may be added or removed from the beginning or middle as well, use LinkedList. If you need to randomly access elements from the middle rather than beginning or end (i.e. access by index rather than sequentially with an iterator) then use an array or ArrayList rather than a LinkedList. If these guidelines contradict for your particular application, then try both and see which is faster. (Good to do this anyway if you have time.) See Tom's article here for more info.
"I'm not back." - Bill Harding, Twister
Joined: Jan 10, 2002
The reason I was thinking of using Vectors is simply because it's size is dynamically set instead of having to be set initially like an Array. The list is only used temporarily so I want to use a structure that not only use minimal space but doesn't effect execution time at all. Which one is better for this?
Joined: May 05, 2000
USe an ArrayList, not an array, if you want a dynamic sized container. Don't worry about performance unless performance is a problem.
FYI: An array is the underlying data structure of a Vector and of an ArrayList. If you're curious about how that all works, I recommend taking a look at the source code (which hopefully can be found in a src.jar or src.zip file in your JDK installation).