The basic difference between an array
and an ArrayList
is that an array has fixed size, whereas, ArrayList
can dynamically grow in size as needed. So, if you are assured that your array size won't change, then you can use it. But if you want to add elements later then a an ArrayList
which is an implementation of List
interface, is the way to go.
Although an ArrayList
is internally backed by an array
only. So, internally it also uses a fixed size array, with an initial capacity of 10 (which can change for that matter), but that detail is internally hidden. So, you don't have to bother about the changing size of the ArrayList
.
Whenever you add elements more than the current size of array in your ArrayList
, the internal array is extended. That means, the regular expansion of size can become an overhead, if you are regular inserting a large number of elements. Although this is rarely the case. Still, you can also give your own initial size while creating an ArrayList
. So, that's upto you to decide.
As for Vector
vs ArrayList
discussion, yes Vector
is now deprecated (not technically though, but it's use is discouraged as stated in comments by @Luiggi), and you should use an ArrayList
. The difference is that Vector
synchronizes each operation, which is nearly never required. When you need synchronization, you can always create a synchronized list using Collections.synchronizedList
.
For more on this discussion, see this post.
An ArrayList
is an implementation of List
. There are other variations too. Like you also have a LinkedList
, to get the functionality of a traditional linked list.