Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Arrays, Arraylist and vector

 
Chandan V. Singh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Greeting to all..

my question is :
among Arrays, Arraylist and vector; which one would be the best choice and under what circumstance ?

TIA
Chandan
 
Steve Morrow
Ranch Hand
Posts: 657
Clojure Spring VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
among Arrays, Arraylist and vector; which one would be the best choice and under what circumstance ?

The "best" choice in my opinion would be the one that allows you to accomplish your programming goal(s) in an effective, efficient, maintainable manner. As such, the choice is dependent on the situation (though I'd generally only use Vector when I was forced to by the API, not by choice).

Prefer ArrayList to Vector. Both offer the same interface (i.e., List), but Vector is an outdated class that was shoehorned into the Collection API. If you absolutely need to have your List synchronized, use Collections.synchronizedList().

The Java� Tutorial - Arrays
Java� Collections Framework
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

A very condensed guide:

Use an array if you're working with a known, fixed number of elements of a uniform type. Use an ArrayList if the number of elements is variable or not known in advance. Use a LinkedList if you have a list which to which you'll frequently add elements in the middle or delete elements from the middle.

Don't use Vector in new code, ever. ArrayList is intended as its replacement.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic