Hi, Can anybody please tell me the difference between Vetor and ArrayList. Because only difference that I know is that Vector is synchronized and ArrayList does not. I did not also understand the meaning of this.
To a large extent the fact that an ArrayList is not synchronized, is the major difference. This provides a slight performance enhancement above java.util.Vector.
Synchronization prevents two threads from modifying the data held by the Vector at the same time, hence maintaining data integrity.
Hello, Thanks for reply. ArrayList is not synchronized but still generally we go for ArrayList. Why is it so? Infact when should we use ArrayList and when Vector.
Vectors are legacy collections, so I'd say don't use them at all. If you need a synchronized List, use the static convenience method Collections.synchronizedList(List list).
Hi, If I am not wrong Vector, Stack, Dictionary, HashTable, Properties, Enumeration are all legacy collections. Should we not go for all legacy collections.
Dictionary, I'd never use (and programmers are directed thus by the API JavaDocs). By extension the same goes for Hashtable. Stack its just an extension of Vector so probably not. But a Stack is a collection which behaves somewhat differently from any of the new collections so there might be a case for using it. Same goes for Properties objects, which can be useful. They are really more than just a collection because they offer as route to load properties from the file system.