• 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

Vector Vs ArrayList

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can anybody answer the following question.

"Difference between Vector and ArrayList other than Synchronization?"

Thanks in Advance,
LALITH
 
Ranch Hand
Posts: 904
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

well...

ArrayList

java.lang.Object
|
+--java.util.AbstractCollection
|
+--java.util.AbstractList
|
+--java.util.ArrayList

All Implemented Interfaces:
Cloneable, Collection, List, Serializable
-----------------------------------------------------------------------
Vector

java.lang.Object
+-- java.util.AbstractCollection
+-- java.util.AbstractList
+-- java.util.Vector

All Implemented Interfaces:
Cloneable, Collection, List, RandomAccess, Serializable
-----------------------------------------------------------------------

As you can see: They arn't that different (except from the fact that the
ArrayList isn't synchronized - which, btw., is quite important to know)


If you have any follow up questions then I'll gladly try to answer them.

/Svend Rost
[ October 06, 2004: Message edited by: Svend Rost ]
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as I know, they have different behaviour when they need to resize. Take a look at the source code...
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


ArrayList

java.lang.Object
|
+--java.util.AbstractCollection
|
+--java.util.AbstractList
|
+--java.util.ArrayList

All Implemented Interfaces:
Cloneable, Collection, List, Serializable



for a little notification:
ArrayList also implements the RandomAccess interface
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd like to emphasize a previous comment: ArrayList isn't synchronized for mult-threading whereas Vector is. IMHO, this is the most distinctive difference between these to classes.

Layne
 
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seriously speaking, being sychronized doesn't make vector totally thread-safe. So don't get carried away & start using vector all over the places thinking that you're thread-safe.

For better performance, I'd suggest using ArrayList & then synchronizing the method or codes that handles it.

Just my 2c
 
Yeltek Tsai
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Seriously speaking, being sychronized doesn't make vector totally thread-safe.


hmm...this makes me confused.
what do you mean "not totally thread-safe" ? is there any bug or flaw in the Vector ? as i know, Vector has some performance hits bcz of the thread-safe considerations. if it is still not safe, there will be no reason to use Vector instead of ArrayList.
reply
    Bookmark Topic Watch Topic
  • New Topic