| 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: 24061
|
|
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]
|
 |
 |
|
|
subject: Arrays, Arraylist and vector
|
|
|