aspose file tools*
The moose likes Beginning Java and the fly likes Array lists vs Vectors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array lists vs Vectors " Watch "Array lists vs Vectors " New topic
Author

Array lists vs Vectors

sujay kulkarni
Greenhorn

Joined: Oct 04, 2012
Posts: 15
when to use arraylist and when to use Vectors ?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

moving to beginning java forum.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Only use Vector when you have no choice, when interacting with code that requires it.

Vector was created before the Collections Framework was added in 1.2, and was then retrofitted into it. ArrayList was created as part of the Collections framework from its beginning. Though both classes implement List, Vector also has a bunch of methods that are not part of the standard List interface, going back to its days before the Framework was defined. Vector will function just as well as ArrayList in most or all situations, but the general consensus now is to avoid it. If somebody sees it in your code, they're going to wonder why you're using it--whether you had a good reason to use it, or if you just didn't know that ArrayList is now preferred.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3649
    
  17

Use ArrayLists when you need any old ordered collection, or when you need good random-access times.

Use Vectors when the API you're working with specifically needs them. I believe this is still the case for some classes in the Swing API, for example. *Never* use them when you're working with new code.

Other alternatives are always better than Vector. For regular use, ArrayList is better. For synchronized use with many edits, use Collections.synchronizedList(arrayList). For synchronized use with many traversals, use CopyOnWriteArrayList.
sujay kulkarni
Greenhorn

Joined: Oct 04, 2012
Posts: 15
Thanks a ton !! everyone for your help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array lists vs Vectors