Monday, October 6, 2008

What is java collections framework?

Collection Framework:

Collections basically hold data in a single unit. It might be various kinds of data, and all of the heterogeneous data can be stored as Objects in a single unit called Collection.

Collections Mainly Consist of 3 different parts: -

Interfaces – Allows collections to be manipulated independently of their implementations. Fig (1.1)

Implementations – The concrete classes that are implementations of the interfaces.

Utility Methods – Static methods used for sorting, searching or creating customized collections. E.g. Collections. Sort (Collection)











Core Interfaces of Collections framework

Collection – A basic interface that defines the normal operations that allows a collection of objects to be maintained or handled as a single unit.

Set – Just like mathematics: a set of unique elements. Contains only unique elements and no duplicates. (HashSet, LinkedHashSet)

Sorted Set – Extends set to provide sorted elements in set. (TreeSet)

List – Order of elements is retained. Elements need not be unique. (ArrayList, Vector, LinkedList)

Map – Contains a key and value pair. (HashMap, HashTable, LinkedHashMap)
Sorted Map – Extends Map to store mappings sorted in key order. (TreeMap)


Implementations

Each of collection classes has a constructor for creating a collection based on elements of another collection object passed as argument.
Collection (or map) stores only the references and not the actual objects.
Collection framework is interface based i.e collections are manipulated according to interface types rather than implementations types.
All concrete classes implement Serializable and Cloneable interfaces.

No comments: