• Post Reply Bookmark Topic Watch Topic
  • New Topic

Difference between Vector and ArrayList  RSS feed

 
Mahesh Malviya
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks and Regards
Mahesh Malviya
 
Oscar Reitsma
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mahesh Malviya
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

bye
Mahesh Malviya
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Mahesh Malviya
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If I am not wrong Vector, Stack, Dictionary, HashTable, Properties, Enumeration are all legacy collections. Should we not go for all legacy collections.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!