Easy Tutorial
For Competitive Exams

Java Programming Collection

Why Collection Framework?

Collections are nothing but group of objects stored in well defined manner.

Earlier, Arrays are used to represent these group of objects. But, arrays are not re-sizable.Size of the arrays are fixed. Size of the arrays can not be changed once they are defined.

This causes lots of problem while handling group of objects.

To overcome this drawback of arrays,Collection framework or simply collections are introduced in java from JDK 1.2.

What is Collection Framework In Java?

Collection Framework in java is a centralized and unified theme to store and manipulate the group of objects.

Java Collection Framework provides some pre-defined classes and interfaces to handle the group of objects.

Using collection framework, you can store the objects as a list or as a set or as a queue or as a map and perform operations like adding an object or removing an object or sorting the objects without much hard work.

Class Hierarchy Of Collection Framework :

All classes and interfaces related to Collection Framework are placed in java.util package.

java.util.Collection class is at the top of class hierarchy of Collection Framework.

Three of above interfaces (List, Queue and Set) inherit from Collection interface. Although, Map and Iterator is included in collection framework it does not inherit from Collection interface.

List

A List is an ordered Collection (sometimes called a sequence).

Lists may contain duplicate elements.

Elements can be inserted or accessed by their position in the list, using a zero-based index.

ArrayList, Vector and LinkedList classes implement this interface.

Queue

It handles special list of objects in which elements are removed only from the head.

LinkedList and PriorityQueue classes implement this interface.

Set

A Set is a Collection that cannot contain duplicate elements.

There are three main implementations of Set interface: HashSet, TreeSet, and LinkedHashSet.

Map

A Map is an object that maps keys to values.

A map cannot contain duplicate keys.

There are three main implementations of Map interfaces: HashMap, TreeMap, and LinkedHashMap.

Iterator/ListIterator

Both Iterator and ListIterator are used to iterate through elements of a collection class.

Using Iterator we can traverse in one direction (forward) while using ListIterator we can traverse the collection class on both the directions(backward and forward).

Solve this!!

#20072,20073,20074,20075
Share with Friends