The Java collections framework is a set of classes and interfaces that implement commonly reusable collection data structures (collections). Although referred to as a framework, it works in a manner of a library. The collections framework provides both interfaces that define various collections and classes that implement them.
Differences from Arrays Collections and arrays are similar in that they both hold references to objects and they can be managed as a group. However, unlike arrays, Collections do not need to be assigned a certain capacity when instantiated. Collections can grow and shrink in size automatically when objects are added or removed. Collections cannot hold primitive data types such as int, long, or double. Instead, Collections can hold wrapper classes such as java.lang.Integer, java.lang.Long, or java.lang.Double. Collections are generic and hence invariant, but arrays are covariant. This can be considered an advantage of generic objects such as Collection when compared to arrays, because under circumstances, using the generic Collection instead of an array prevents run time exceptions by instead throwing a compile-time exception to inform the developer to fix the code. For example, if a developer declares an Object[] object, and assigns the Object[] object to the value returned by a new Long[] instance with a certain capacity, no compile-time exception will be thrown. If the developer attempts to add a String to this Long[] object, the java program will throw an ArrayStoreException. On the other hand, if the developer instead declared a new instance of a Collection<Object> as ArrayList<Long>, the Java compiler will (correctly) throw a compile-time exception to indicate that the code is written with incompatible and incorrect type, thus preventing any potential run-time exceptions.The developer can fix the code by instantianting Collection<Object> as an ArrayList<Object> object. If the code is using Java SE7 or later versions, the developer can instantiate Collection<Object> as an ArrayList<> object by using the diamond operator Collections are generic and hence reified, but arrays are not reified.
History Collection implementations in pre-JDK 1.2 versions of the Java platform included few data structure classes, but did not contain a collections framework. The standard methods for grouping Java objects were via the array, the Vector, and the Hashtable classes, which unfortunately were not easy to extend, and did not implement a standard member interface. To address the need for reusable collection data structures, several independent frameworks were developed, the most used being Doug Lea's Collections package, and ObjectSpace Generic Collection Library (JGL), whose main goal was consistency with the C++ Standard Template Library (STL). The collections framework was designed and developed primarily by Joshua Bloch, and was introduced in JDK 1.2. It reused many ideas and classes from Doug Lea's Collections package, which was deprecated as a result. Sun Microsystems chose not to use the ideas of JGL, because they wanted a compact framework, and consistency with C++ was not one of their goals. Doug Lea later developed a concurrency package, comprising new Collection-related classes. An updated version of these concurrency utilities was included in JDK 5.0 as of JSR 166.
Architecture Most collections in Java that are not maps are derived from the java.util.Collection interface. Collection defines the basic parts of all collections. The interface has the add(E e) and remove(E e) methods for adding to and removing from a Collection respectively. It also has the toArray() method, which converts the Collection into an array of Objects in the Collection (with return type of Object[]). Finally, the contains(E e) method checks if a specified element exists in the Collection. The Collection interface is a subinterface of java.lang.Iterable, so any Collection may be the target of a for-each statement. (The Iterable interface provides the iterator() method used by for-each statements.) All Collections implement java.util.Iterator to scan all of the elements in the Collection. Collection is generic. Any Collection can store any Object. For example, any implementation of Collection<String> contains String objects. No casting is required when using the String objects from an implementation of Collection<String>. Note that the angled brackets < > can hold a type argument that specifies which type the Collection holds. Collection Framework Collection Framework just holds all the collections (general concept) like list etc, which follows collection interface. Types of collection There are several kinds of collections: queues, maps, lists and sets. Queues allow the programmer to insert items in a certain order and retrieve those items in the same order. An example is a waiting list. The base interfaces for queues are called Queue. Dictionaries/Maps store references to objects with a lookup key to access the object's values. One example of a key is an identification card. The base interface for dictionaries/maps is called Map. Lists are finite collections where it can store the same value multiple times. Sets are unordered collections that can be iterated and contain each element at most once. The base interface for sets is called Set.
List interface Lists are implemented in the collections framework via the java.util.Listinterface. It defines a list as essentially a more flexible version of an array. Elements have a specific order, and duplicate elements are allowed. Elements can be placed in a specific position. They can also be searched for within the list.
List implementations There are several concrete classes that implement List, including AbstractList and all of its corresponding subclasses, as well as CopyOnWriteArrayList.
AbstractList class The direct subclasses of AbstractList class include AbstractSequentialList, ArrayList and Vector. AbstractList is an example of a skeletal implementation, which leverages and combines the advantages of interfaces and abstract classes by making it easy for the developer to develop their own implementation for the given interface.
ArrayList class The java.util.ArrayList class implements the List as an array. Whenever functions specific to a List are required, the class moves the elements around within the array in order to do it.
… excerpt ends here. Continue reading the full article.


