Close

Java - What is Collections Framework?

[Updated: Feb 8, 2017, Created: Apr 19, 2016]

The Java Collections Framework is a set of interfaces and classes, reside in the packages: java.util and java.util.concurrent

The Collection API provides various models of how to organize group of objects.

These models are represented as interfaces. These models are generally known as Abstract Data Type. For example java.util.List is a sequential group of object. 'Abstract Data Type' concepts are independent of any programming language.

Concrete implementations of these interfaces uses a particular Data Structure. For example java.util.ArrayList uses 'an array of objects' as underlying 'data structure'.


collections-framework


Why we need this framework?

We need collection framework because different programs need different ways of organizing their objects as a group.

In one situation, we might want to organize objects in a sequential list because their ordering is important and there are duplicates.

In another situation, a set (just like mathematical set) abstract data type might be appropriate because now ordering is unimportant and you want to discard the duplicates.

These two data types (and others) are represented by different interfaces in the Collections Framework, and we will look at them in next tutorials.

Also deciding about 'abstract data type' is not the whole story, a particular implementation (data structure and algorithm) might be better than others in a particular situation. For example, a linked list data structure may be better than an array implementation of lists for inserting and removing elements from the middle, but much worse for random access. So choosing the right implementation is also very important.




java.util.Collections

Other than getting to know all interfaces and their implementations, we have to know java.util.Collections class as well.

This class contains polymorphic algorithms that operate on the provided collections. For example Collections.sort(..) methods.

It also contains methods which return a new 'wrapper' instance of the provided collection. For example Collections.synchronizedCollection(..)

See Also