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

Array vs List vs Vector

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

In most of my applications I have been using Arrays and Lists to store my objects. I usually use Arrays for a temp storage area until I am ready to put them in a List since a List is dynamic and can grow and shrink.
I took a look at the Vector API and it looks very similar to that of List. Could anyone tell me if one is better than the other for storing String Objects in memory?
What would be the pros and cons of Vector vs List.
Thanks

------------------
Happy Coding,
Gregg Bolinger


GenRocket - Experts at Building Test Data
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

Gregg:
I am moving this thread to the Java In General, Intermediate forum. Please continue the discussion in that forum.
Thanks.
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Use ArrayList if you are not concerned about access to your elements while you are processing them. Vector is synchronized. That's the major difference that I am aware of. The Vector class is also deprecated in favor of ArrayList.

Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

That is very helpful. Thank you cery much!!

------------------
Happy Coding,
Gregg Bolinger
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
If you need a synchronized data structure, I would suggest Collections.synchronizedList(new ArrayList()) in preference to a Vector.
- Peter
Reuben Cleetus
Ranch Hand

Joined: Jul 13, 2001
Posts: 50
Bosun, are you sure that the Vector class is deprecated?!? Where did you find this out? Is it marked as deprecated in JDK 1.4, because it's not in 1.3.1.
Can anyone confirm?
Regards,
Reuben.
Originally posted by Bosun Bello:
Use ArrayList if you are not concerned about access to your elements while you are processing them. Vector is synchronized. That's the major difference that I am aware of. The Vector class is also deprecated in favor of ArrayList.

Bosun

Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
You are correct Gregg. The Vector class is not deprecated as I previouly posted.

Bosun
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Array vs List vs Vector