Complete chapters of
Java books have been written on this subject, so any answer we can give here would be a high level summary. Here is such a summary:
"Collections" is an all encompassing term. The
Java Collections Framework API consists of various interfaces and classes to create and use common data structures, Lists, stacks, maps, etc. You can read more about the collections API in the Java documentation (see above link), and learn more about it in the
Collections Trail of
Sun's online Java Tutorial, or in Chapter 11 of the opensource (i.e. free) e-book
Thinking in Java.
An ArrayList and a Vector are very similar. The Vector class has been a part of Java since the beginning (i.e. since JDK1.0). The Java Collections Framework was added in Java version 1.2. The ArrayList was part of the Java Collections Framework. The ArrayList class was designed from the ground up to work as part of the Collection Framework and all its common interfaces, whereas the Vector class had to later be retrofitted into the Collections Framework. A
primary difference between a Vector and an ArrayList is that Vector is synchronized whereas ArrayList is not. Synchronization has to do with threading. Generally, unless there is a specific reason not to,
you should use an ArrayList rather then a Vector (and this holds pretty true for new developers, until they get into more complex issues/code in which there is a reason to use a Vector.) Like all collections classes, Vectors and ArrayLists can only hold objects. They cannot hold primitives directly; primitives need to be wrapped with a wrapper class such as Integer for an int. Java 5.0 does this "automatically" via a feature called autoboxing.
An Array, which in Java is an object, is not part of the Collections framework. While Arrays are can hold objects or primitives, they are most useful with primitives. Because an Array is not part of the Collections API, they are a little bit less flexible. Also, one of the biggest shortcomings of an Array is that it is fixed in size. You cannot expand or contrast an Array. So if you make an Array to hold 10 items, and you suddenly need to put in 11, you need to create a new Array of size 11, copy all the items over, then add your 11th item. This can be a costly operation. ArrayLists (and Vectors) on the other hand can grow and shrink as needed. Therefore ArrayLists are far more useful to hold dynamic collections, or collections where the size is hard to predetermine.
Take a look at the Sun Java Tutorial and the
Thinking in Java links above. They should help you to understand in more detail the differences of the items. You can also try a Google search using the terms
ArrayList Vector difference Java and
ArrayList Array difference Java to find some other articles and information. Also
search the "Java in General (Beginner)" forum here using the search
ArrayList Vector difference and you will find a dozen or so threads discussing the differences.
[ July 17, 2005: Message edited by: Mark Vedder ]