Saturday, 6 October 2012

Java Collections Framework


A collection is an object that represents a group of objects and it is a unified architecture for representing and manipulating collections

Advantages of having a collections framework

Reduces programming effort by providing useful data structures and algorithms
Increases performance by providing high-performance data structures and algorithms
Interoperability between the different collections
Having a common language for manipulating the collections

Collection Classes

This group of classes represent various data structures used to store and manage objects and their underlying implementation is implied in the class names, such as ArrayList and LinkedList .Several interfaces are used to define operations on the collections, such as List, Set, SortedSet, Map, and SortedMap

Components of Java Collections Framework

Collection Interfaces: form the basis of the framework  such as sets, lists and maps
Implementations Classes: implementations of the collection interfaces
Utilities: Utility functions for manipulating collections such as sorting, searching…

Collections Interfaces

          Hash tables (map)


Interface: Collection

The Collection  interface is the root of the collection hierarchy

public interface Collection {
    // Basic Operations
    int size();
    boolean isEmpty();
    boolean contains(Object element);
    boolean add(Object element);    
    boolean remove(Object element); 
    Iterator iterator();
    // Bulk Operations
    boolean containsAll(Collection c);
    boolean addAll(Collection c);    
    boolean removeAll(Collection c); 
    boolean retainAll(Collection c); 
    void clear(); 
    // Array Operations
    Object[] toArray();
    Object[] toArray(Object a[]);