File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Arrays, Arraylist and vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Arrays, Arraylist and vector" Watch "Arrays, Arraylist and vector" New topic
Author

Arrays, Arraylist and vector

Chandan V. Singh
Greenhorn

Joined: Sep 14, 2005
Posts: 1
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

Joined: May 22, 2003
Posts: 657

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

Joined: Jul 08, 2003
Posts: 24184
    
  34

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.


[Jess in Action][AskingGoodQuestions]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Arrays, Arraylist and vector