Collections in Java

Collections in java is a framework that provides an architecture to store and manipulate the group of objects.

All the operations that you perform on a data such as searching, sorting, insertion, manipulation, deletion etc. can be performed by Java Collections.

Java Collection simply means a single unit of objects. Java Collection framework provides many interfaces (Set, List, Queue, Deque etc.) and classes (ArrayList, Vector, LinkedList, PriorityQueue, HashSet, LinkedHashSet, TreeSet etc).

Collection represents a single unit of objects i.e. a group.

What is framework in java

  1. provides readymade architecture.
  2. represents set of classes and interface.
  3. is optional.

What is Collection framework

Collection framework represents a unified architecture for storing and manipulating group of objects. It has:

  1. Interfaces and its implementations i.e. classes
  2. Algorithm

Hierarchy of Collection Framework


Methods of Collection interface

  1. public boolean add(Object element)

    is used to insert an element in this collection.

  2. public boolean addAll(Collection c)

    is used to insert the specified collection elements in the invoking collection.

  3. public boolean remove(Object element)

    is used to delete an element from this collection.

  4. public boolean removeAll(Collection c)

    is used to delete all the elements of specified collection from the invoking collection.

  5. public boolean retainAll(Collection c)

    is used to delete all the elements of invoking collection except the specified collection.

  6. public int size()

    return the total number of elements in the collection.

  7. public void clear()

    removes the total no of element from the collection.

  8. public boolean contains(Object element)

    is used to search an element.

  9. public boolean containsAll(Collection c)

    is used to search the specified collection in this collection.

  10. public Iterator iterator()

    returns an iterator.

  1. public boolean hasNext()

    It returns true if iterator has more elements.

  2. public Object next()

    It returns the element and moves the cursor pointer to the next element.

  3. public void remove()

    It removes the last elements returned by the iterator. It is rarely used.


Copyright 2017 Design& Development