• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference between Vector and ArrayList

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic