Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array vs List vs Vector

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Gregg:
I am moving this thread to the Java In General, Intermediate forum. Please continue the discussion in that forum.
Thanks.
- satya
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is very helpful. Thank you cery much!!

------------------
Happy Coding,
Gregg Bolinger
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you need a synchronized data structure, I would suggest Collections.synchronizedList(new ArrayList()) in preference to a Vector.
- Peter
 
Reuben Cleetus
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct Gregg. The Vector class is not deprecated as I previouly posted.

Bosun
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic