permaculture playing cards*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 24183
    
  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]
 
Consider Paul's rocket mass heater.
 
subject: Arrays, Arraylist and vector
 
Similar Threads
vector and array list
huge recordset problem
Regarding ArrayList and Vector
vector and array list
How to implement expandable array