my dog learned polymorphism
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes ArrayList vs. Vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "ArrayList vs. Vector" Watch "ArrayList vs. Vector" New topic

ArrayList vs. Vector

Wickes Potgieter
Ranch Hand

Joined: Apr 05, 2002
Posts: 68
I am trying to come up with a good explination for my choices.txt and would appreciate some comments.
In my DBAdapter class, I have a method which returns a list of contractors but am not sure if I should return the list as an ArrayList or Vector. Which will be the best to use...? and why?
Both have dynamic sizing capabilities, but Vectors are synchronized...
Thank you in advance...

Wickes Potgieter<br />SCJP<br />BEA Certified Specialist: Server, Integration, Portal, Tuxedo<br />BEA WebLogic Server 7 Certified Enterprise Developer<br />BEA Certified Architect<br /><a href="" target="_blank" rel="nofollow"></a>
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
hi Wickes:
Sun documentation refers to ArrayList, HashMap, and HashSet as being the preferred "primary implementations". Their overall performance is better, and you should use them unless you need a special feature provided by another implementation. In general, Vector is slower because all of its methods are sync. Regular array are lighter wieght than any other collection class. If you find arrays fit your needs, you should consider them first, otherwise you should looke for the appropriate collection calss.
[ May 10, 2004: Message edited by: Hanna Habashy ]

SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Wickes Potgieter
Ranch Hand

Joined: Apr 05, 2002
Posts: 68
Thank you for your response!!
I agree. Here's the link:
subject: ArrayList vs. Vector
jQuery in Action, 3rd edition