• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

vector or arrayList

 
kishor kalapa
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is use of vector or arrayList which one increase performance speed
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vector access methods are synchronized so it is slightly slower.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And typically the synchronization of Vector is worse than useless anyway (in the sense that it gives false confidence to people who don't really know what they're doing). And there is really, really, no reason to use Vector in the modern age unless you're forced to because you're being paid to use a badly outdated API. Even then: just say no. We'll all be happier.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18226
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Back in 2001 I used Vector, but that's because there were no Collection classes such as ArrayList. So I have a fair amount of legacy code that uses it and it's not worth the trouble to convert.

However, all my new code uses collection classes. They're more flexible and have less overhead. And, one nice thing about them is that I can slap synchronization on them at need while not being punished when I don't need it.

Vector was redefined slightly to make it more conformant with the Collection classes. This happened in Java 1.3 or 1.4, I think. But since synchronization is one of its basic defined characteristics, I wouldn't use it in new code unless it was appropriate.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:Back in 2001 I used Vector, but that's because there were no Collection classes such as ArrayList.

Well, ArrayList was available as part of JDK 1.2, which came out in December 1998. Prior to that it was available as part of the Collections extension that you could download separately from Sun. When these were released as part of JDK 1.2, that's also when they added some new methods to Vector to implement the new List interface.

Anyway, I agree there's often no point to updating legacy code to replace Vector with ArrayList. I just take a somewhat aggressive stand against using Vector in any new code, nowadays.
 
Billy Tsai
Ranch Hand
Posts: 1304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is CopyOnWriteArrayList from the Java Cocurrent Package in Java 5 faster than Vector and ArrayList?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic