Overview of Java Collections Framework

Collections Framework is a good example of implementation of Data Structures. It has benefited many and saved a lot of efforts from many developers from re-implementing the same thing over and over again. Also, it has helped saved companies millions of dollars, right from developers efforts to performance team efforts from trying to analyze the performance of different implementation from different developers.

The framework was designed keeping several aspects into consideration, but the most important once
1. It offered various implementation via interfaces so one can use based on their needs.
2. The framework had to be of high performance and the implementations highly efficient.
3. Making it extendable so more and more developers can adapt to it very easily.

The below two diagrams define the whole Collection Framework in short

Java Collections


Collection: Collection is the core interface of Collections Framework. Collection interface is the core which has methods like size(), isEmpty(), contains(Object obj), add(E obj), remove(Object obj). It also has an iterator which helps one iterate through the collection exposed as Iterator iterator(). When you want to perform operations in bulk, collection interface provides addAll(Collection collection), removeAll(Collection collection), retainAll(Collection collection), containsAll(Collection collection) and clear().

Set: Set cannot contain duplicate elements. It has further implementations like HashSet (elements are stored in HashTable), TreeSet (stores elements ordered based on their values), and LinkedHashSet (it uses HashTable and Linked List to store its elements, elements are stored based on order of insertion).

List: List can contain duplicate elements. List add further operations like get, set, add, remove, indexOf, lastIndexOf and remove, to name a few. List also has following algorithms already implemented so developers are saved from re-writing them again and again like sort(), reverse(). fill(), copy(), binarySearch() to name a few.

Map: Map cannot contain duplicate keys. Map is a collection which stores object in key-value pairs. It has further implementations like HashMap, TreeMap and LinkedHashMap.

This site uses Akismet to reduce spam. Learn how your comment data is processed.