• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Array lists vs Vectors

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when to use arraylist and when to use Vectors ?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
moving to beginning java forum.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 14488
325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a ton !! everyone for your help
 
Not so fast naughty spawn! I want you to know about
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic