This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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 theThinking 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 ]
An ArrayList is a non-thread safe array whose size can dynamically change during run-time. Its really an array which is shifted into another array at least one size bigger than the original during run-time.
A vector is similar to an ArrayList, but with thread-safe capability. So any thread working on a vector will do so in knowledge that no other thread will be working on any object referenced from within the vector.
Do you understand the basic difference between an interface and a class? "Collection" (capital C) is an interface that various classes implement (e.g., Vector, ArrayList, TreeSet, etc.) -- hence, all of these classes can be used interchangeably anywhere in a program that a Collection is required.
The term "collection" when used in general refers to an object designed to hold onto references to other objects, just like an egg carton is a special type of object designed to hold other objects (eggs). There are other classes in Java that *don't* implement the Collection interface, but which nonetheless serve as a collection in the lower-case c sense of the word: e.g., Array, TreeMap, etc.