The Collections Framework

 In this section you should be able to:

1.      Make appropriate selection of collection classes/interfaces to suit specified behaviour requirements.

2.      Distinguish between correct and incorrect implementations of hashcode methods.

 

The Collections framework

A collection allows a group of objects to be treated as a single unit. Collections define a set of core interfaces. These are:-

·        Collection

·        Set

·        List

·        SortedSet

·        Map

·        SortedMap

Collections also provide implementation for these interfaces.

 

Core interfaces

The object hierarchy of Core interfaces defined in Collections is given below.

 

Figure: Core Interfaces of Collections

 

Collection Interface

The Collection interface is the root of Collection hierarchy, and is used for common functionality across all collections. There is no direct implementation of the Collection interface.

 

Set Interface

The Set interface is used to represent a group of unique elements. It extends the Collection interface. The class HashSet implements the Set interface.

 

SortedSet Interface

The SortedSet interface extends the Set interface. It provides extra functionality of keeping the elements sorted. So SortedSet interface is used to represent collections consisting of unique, sorted elements. The class TreeSet is an implementation of interface SortedSet.

 

List Interface

The List interface extends the Collection interface to represent sequence of numbers in a fixed order. Classes ArrayList, Vector and LinkedList are implementations of List interface.

 

Map Interface

The Map interface is a basic interface that is used to represent mapping of keys to values. Classes HashMap and Hashtable are implementations of Map interface.

 

SortedMap Interface

The SortedMAp interface extends Map interface and maintains their mappings in key order. The class TreeMap implements SortedMap interface.

 

The table below give a list of Collection interfaces and the classes that implement them.

 

Interface

Class Implementation

Set

HashSet

SortedSet

TreeSet

List

ArrayList, Vector, Linked List

Map

HashMap, Hashtable

SortedMap

TreeMap

 

 

back