File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Performance and the fly likes vector or arrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "vector or arrayList " Watch "vector or arrayList " New topic

vector or arrayList

kishor kalapa

Joined: Jun 05, 2008
Posts: 24
Is use of vector or arrayList which one increase performance speed
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
Vector access methods are synchronized so it is slightly slower.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3028
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

Joined: Jun 25, 2001
Posts: 17417

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.

An IDE is no substitute for an Intelligent Developer.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3028
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

Joined: May 23, 2003
Posts: 1304
is CopyOnWriteArrayList from the Java Cocurrent Package in Java 5 faster than Vector and ArrayList?

BEA 8.1 Certified Administrator, IBM Certified Solution Developer For XML 1.1 and Related Technologies, SCJP, SCWCD, SCBCD, SCDJWS, SCJD, SCEA,
Oracle Certified Master Java EE 5 Enterprise Architect
I agree. Here's the link:
subject: vector or arrayList
It's not a secret anymore!