• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Array vs List vs Vector

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is very helpful. Thank you cery much!!

------------------
Happy Coding,
Gregg Bolinger
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are correct Gregg. The Vector class is not deprecated as I previouly posted.

Bosun
 
Come have lunch with me Arthur. Adventure will follow. This tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic