wood burning stoves 2.0*
The moose likes Java in General and the fly likes Vector deprecated in 1.3? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Vector deprecated in 1.3?" Watch "Vector deprecated in 1.3?" New topic

Vector deprecated in 1.3?

Joe McGuire
Ranch Hand

Joined: Mar 19, 2001
Posts: 293
I heard from a colleague that the Vector class was deprecated in Java 1.3? Is that true? What has replaced it?
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
How hard is it for you to open Docs and look it up ? it takes a second to do. No it hasn't been depricated and it will not be because for one reason of multithreading. Other wise you should always use ArrayList which is a lot faster then Vector.

Val SCJP <BR>going for SCJD
Bhushan Shete

Joined: Mar 20, 2001
Posts: 9
Actually, you can use Collections instead of Vectors. However, you can still use Vectors, but then the problem is that, by default Vectors are synchronised & are very slow. So, it's better to use Collections.
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
Vector is considered to be a Collection just a type of List.
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Vector was re-worked to implement Collection. If you need synchronization use Vector, otherwise Sun recommends that you use ArrayList.

"JavaRanch, where the deer and the Certified play" - David O'Meara
Peter Tran

Joined: Jan 02, 2001
Posts: 783
This question of whether Vector has been deprecated in JDK1.3 has already been answered, so I don't need to bring it up again.
Cindy's comment is totally valid, but from my experience I rarely had to make use of a Vector - even in a multi-threaded environment. Here's my justification.
1. Most collections are use to hold static data from a file or database table (e.g. internal cache).
2. The collection is usually populate once - read many.
If both 1 and 2 are true (which I believe is true over 90% of the time), then you should use an ArrayList. I would synchronized the method that is populating the ArrayList. After populating the ArrayList, you can use the Collections.synchronizedList(ArrayList) to get a synchronized list for reading by multiple threads. IMO, this approach is faster than using a Vector.
Just $0.02,
ken chou
Ranch Hand

Joined: Feb 08, 2001
Posts: 68

In terms of what they can do. Is "synchronization" the only difference between the Vector and ArrayList?
ryan burgdorfer
Ranch Hand

Joined: Jan 24, 2001
Posts: 219
A big difference apparent from a glance at the API is that Vector has alot more methods than ArrayList...take a look, you'll see.

  • Ryan Burgdorfer
  • Java Acolyte in
  • Columbus, OH USA

<UL TYPE=SQUARE><I><LI>Ryan Burgdorfer<BR><LI>Java Acolyte</I></UL>
ken chou
Ranch Hand

Joined: Feb 08, 2001
Posts: 68

That's right. Vector has a lot more methods than ArrayList. So in terms of manipulating data, using Vector is a lot more handy than ArrayList, right?
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Not really. Almost all the "extra" methods in Vector are merely trivial renaming of other methods. Well, actually it's the other methods that are renamings, since the Vector methods came first. Example: Vector has elementAt(int) method; when they built ArrayList they renamed this to get(int), and added get(int) to Vector as well even though it does the exact same thing as elementAt(int). They retained the old method name so as not to break existing code, but for new development it's easier to just use the new add(int) method for both ArrayList and Vector.
Anyway, almost everything in Vector is trivial to accomplish under the ArrayList API. The only exceptions I found were:
ArrayList has no constructor to set capacity increment - good, this is almost always a bad idea; exponential growth is much better.
capacity() - umm, so what?
indexOf(Object, int) - use subList + indexOf to mimic
lastIndexOf(Object, int) - use subList + lastIndexOf to mimic
setSize() - probably misunderstood by a lot of people, and not very useful anyway. What's the point of having a growable Collection if you're going to set the size? Might as well use an array in that case.
[This message has been edited by Jim Yingst (edited March 21, 2001).]

"I'm not back." - Bill Harding, Twister
ken chou
Ranch Hand

Joined: Feb 08, 2001
Posts: 68

According to Peter and Jim's Analysis. It seems like we shouldn't use Vector any more.
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
To expand Cindy's post - If you need your collection to be thread-safe or you don't have access to the Java 2 Collections, then use Vector, otherwise use ArrayList.

Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Peter den Haan
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Frank Carver:
To expand Cindy's post - If you need your collection to be thread-safe or you don't have access to the Java 2 Collections, then use Vector, otherwise use ArrayList.

If you need your collection to be threadsafe, think twice before using Vector. I've seen too many greenhorns end up on the wrong side of an angry bull because they thought they were threadsafe by using a Vector.
The fact that a Vector is synchronized means that multiple threads won't make a mess of your Vector. No more, no less. It does not mean that the logic you're building around the Vector is threadsafe. In fact, it usually isn't, but the Vector will lure you into thinking you're OK. And when you've finally debugged your code you will have ended up unnecessarily acquiring monitor locks twice, once in your class, once in the Vector.
My recommendation would be to always use an ArrayList instead, and to carefully synchronize those actions that need synchronizing; no more, no less.
- Peter
I agree. Here's the link: http://aspose.com/file-tools
subject: Vector deprecated in 1.3?