Java – Collections Framework

Prev     Next

  • Collection is an object representing a group of objects.
  • Collection framework contains a set of classes and interfaces which are used for representing and manipulating collections.
  • Collection interface is the root interface from which the interfaces List, Set,Queue are extended.Java Framework

List interface:

  • List interface is an ordered collection in which duplicate elements are also allowed.
  • Elements are stored in a sequential way and hence its elements can be accessed using the index value.
  1. ArrayList
  2. LinkedList
  3. Vector

Set interface:

  • Set is an unordered collection. It does not maintain any order while storing the elements. It does not allow duplicate elements.

Thus if one requires to store a group of unique elements, set can be used.

  1. HashSet
  2. LinkedHashSet
  3. TreeSet

Map interface:

  • Map is an interface which maps keys to values in which each key has to be unique.
  1. HashMap
  2. Hashtable
  3. TreeMap

Retrieving elements from collection:

Iterator interface:

  • Iterator interface is used to iterate over a collection object and retrieve the elements one after the other.

ListIterator interface:

  • ListIterator is similar to Iterator interface except that the elements of the collection can be retrieved from both forward and backward direction.

Enumeration interface:

  • Enumeration interface is similar to Iterator interface except that it cannot remove elements and can only iterate over the collection object.

Iterating using enhanced for loop:

  • Enhanced for loop can also be used to iterate over the collection object.


List<String> places= new LinkedList<String>();

for(String place: places)


Prev     Next

Like it? Please Spread the word!