Collection in Java

Collection Framework has been added in JDK 1.2 and has been expanded in 1.4 -1.6

Interface & Classes of Collection Framework

Collection API provides a group of interface to choose from, but it also gives you some concrete classes to directly play with.

Core Interfaces

Implemented Classes


  • HashMap
  • HashTable
  • TreeMap
  • LinkedHashMap


  • HashSet
  • LinkedHashSet
  • TreeSet


  • ArrayList
  • Vector
  • LinkedList


  • AbstractQueue
    1. ArrayBlockingQueue
    2. ConcurrentLinkedQueue
    3. DelayQueue
    4. LinkedBlockingDeque
    5. LinkedBlockingQueue
    6. LinkedTransferQueue
    7. PriorityBlockingQueue
    8. PriorityQueue
    9. SynchronousQueue


  • ArrayDeque
  • ConcurrentLinkedDeque


Note: Not all the Collection Framework implement the Collection Interface. None of the Map related classes & Interface extend from Collection.

Collections can also be divided in 4 part based on below options

  1. Sorted
  2. Unsorted
  3. Ordered
  4. Unordered



Ordered Collection

An ordered collection can be iterated in a specific order(not-random). E.G.: Array, HashTable

  1. LinkedHashSet (Iteration Order is predictable)
  2. Array
  3. HashTable
  4. ArrayList


Un-Ordered Collection

  1. HashSet


Sorted Collection

In sorted collections order of the collections is determined based to some rules. E.G: List



List Interface

Cares about the index
Has methods related to index(indexOf..)
Ordered by Index postion


List l = new ArrayList<E>();


  • Growable array
  • Fast Iteration
  • Fast Random Access
  • Ordered collection by index
  • Unsorted




Same as an ArrayList but methods in Vector are synchronized.




  • Elements are doubly-linked to each other.
  • Ordered by Index position
  • Good for implementing Stack and Queue
  • Fast Insertion and Deletion



Set Interface

Set is used when uniqueness of the object is to be consider. It doesn’t allow duplicate object. To determine if two objects are equal or not Set uses equals() and hashcode() methods.




  • Unsorted
  • Unordered
  • Uses hashcode of the objects
  • No Duplicate object
  • LinkedHashMap
  • Ordered(Insertion)
  • Uses hashcode of the objects
  • No Duplicate object




  • Sorted(Uses Tree Structure)
  • Uses hashcode of the objects
  • No Duplicate object

Map Interface



Concurrent Collection Interface

  • BlockingQueue extends Queue
  • TransferQueue extends BlockingQueue
  • BlockingDeque extends BlockingQueue
  • ConcurrentMap extends Map

Concurrent Collection Implementation

  • LinkedBlockingQueue extends AbstractQueue implements BlockingQueue
  • ArrayBlockingQueue extends AbstractQueue implements BlockingQueue
  • PriorityBlockingQueue extends AbstractQueue implements BlockingQueue
  • DelayQueue extends AbstractQueue implements BlockingQueue
  • SynchronousQueue extends AbstractQueue implements BlockingQueue
  • LinkedBlockingDeque extends AbstractQueue implements BlockingDeque
  • LinkedTransferQueue extends AbstractQueue implements TransferQueue
  • CopyOnWriteArrayList implements List, RandomAccess
  • CopyOnWriteArraySet extends AbstractSet
  • ConcurrentSkipListSet extends AbstractSet implements NavigableSet
  • ConcurrentHashMap extends AbstractMap implements ConcurrentMap
  • ConcurrentSkipListMap extends AbstractMap implements ConcurrentNavigableMap


Factors that could help on deciding Collection Class

There are various factors that can be considered when selecting an appropriate collection for a particular problem. These factors are:

  1. Ordering – Some sort of ordering in the elements. For example, sorted order, insertion order or no specific ordering.
  2. Duplicates – May or may not want to allow duplicate elements in a collection.
  3. Thread Safe – Ensure the safety of the elements in a collections in case there are multiple threads accessing it.
  4. Key-Value pair – Store in key-value pairs.
  5. Blocking operations – Wait for the collection to become non-empty when retrieving an element.
  6. Random Access – Instant retrieval of an element.
  7. Upper Bounds – To limit the maximum number of elements a collection can hold.

There are also other factors like priority, delay etc..



  1. Collection is a data structure in which Objects are stored.
  2. Objects can be Added, Deleted and can traversed in Collection.
  3. There are 4 type of basic Collection
  4. List : Ordered, Duplicates are allowed, Indexed
  5. Sets : May or may not Ordered. Duplicates are not allowed.
  6. Maps : Duplicate keys are not allowed.
  7. Queue : Ordered by FIFO or priority.
  8. ArrayList : Fast Iteration & Fast Random Access.
  9. Vector: Synchronized Method.
  10. LinkedList : Good for implementing Stack and Queue.
  11. HashSet : Fast Access, No Duplicates, No Ordering.
  12. LinkedHashSet : No Duplicates, Iterates by insertion order.
  13. TreeSet : No Duplicates, Iterates in sorted order.
Series Navigation<< Java Exceptions TutorialJava Hashmap tutorial >>
By | 2017-07-09T12:12:47+00:00 April 20th, 2012|Core Java|23 Comments

About the Author:


  1. anandan June 3, 2013 at 8:02 am - Reply

    i need core java,j2EE full tutorial materials. can you send my email? PLEASE…..

    • sandeepna August 7, 2014 at 5:05 pm - Reply

      Unfortunatly author is replying to girls message only.
      I felt bad about it so repling to your message.

      Check other sites please

      • Vivekanand Gautam August 7, 2014 at 5:59 pm - Reply

        Hi Sandeepna,

        I don’t know why u have this feeling that i only reply to girl. 😛
        May be coz on given article i have replied to a girls msg. Normally i reply on mail and don’t put those messages on blog. But this time i will definitely add this reply on blog. So that no one have this kind of feeling. If i can i always reply to all mails.


      • Sam December 2, 2014 at 10:46 pm - Reply


        • Vivekanand Gautam December 3, 2014 at 11:22 am - Reply

          Not True 😛

      • rk August 14, 2016 at 5:02 am - Reply

        hee…u pepole has 35 % reservation .that y he giving proirty for u …u have to more happy for that :p

  2. Ruchika March 14, 2014 at 11:56 am - Reply

    Please give some information about Map Interface. I have one problem also… i want know about “null interface” is really there is concept like null interface.

    • Vivekanand Gautam March 15, 2014 at 12:18 pm - Reply

      Hi Ruchita,

      This is first time i am hearing about Null Interface. I will check if there is anything like Null interface in Java or not. But as for as my knowledge is concerned there is nothing like it in Java.

      I will try to add Map Interface related details soon if i get time.


      • Ruchika March 18, 2014 at 9:54 am - Reply

        Hi Sir,

        I got some information about null interface in Java, it is as follows:-

        1.Null interface does not contain any abstract method and it has a special meaning for jvm.

        2.Null interfaces act as markers..they just tell the compiler that the objects of this class need to be treated differently.

        3.It gives a message to the java compiler that it can add some special behaviour towards the class which implementing it.

        Eg’s of Marker Interfaces are:-
        – java,lang.Cloneable
        – java,io.Serializable
        – java.util.EventListener

        For Eg:- is a marker interface, it doesn’t contain any method declarations.

        When a java class is to be serialized , i.e when we want to store the state of an object or pass through the network, we should intimate the java compiler in some way that there is a possibility of serializing this java class. For this, marker interfaces are used.

        The java class which needs to be serialized has to implement the marker interface and by doing this we are informing the java compiler to add that capability.

        • Vivekanand Gautam March 18, 2014 at 3:13 pm - Reply

          Hi Ruchika,

          I must admit. I almost forgot about this. Yes i do know about Marker Interface in Java. But i forgot that Marker Interface is also known as Null Interface. Thank you for reminding me. It will be useful for others too.

          Also details provide by you for Marker Interface is quite god. We would love to have you as Writer on our website. 🙂 Do let me know in case you are interested. Feel free to share Articles on different subject with us.


  3. divya October 23, 2014 at 12:35 am - Reply

    your tutorials are very clear when compared to other tutorials available over internet.. Thank u very much for this effort.

  4. Abhijit March 10, 2015 at 5:51 pm - Reply

    Explain More about java.util.concurrent packages

  5. chandan June 23, 2015 at 1:50 pm - Reply

    hii..your tutorials are very clear and easy to understand…

  6. baby jhansi September 12, 2015 at 10:21 am - Reply

    mam can please explain about setters and getters in java..? how and where should we use the setters&getters..?? if we doesn’t use them then what happens..??

    • J Singh September 13, 2015 at 12:20 pm - Reply


      As name suggest setter and getters are used to set and get value of particular property in a class. These are methods inside a class.

      Setter (Set): Set some value in property of class
      Getter (Get): Get value of a property in class.

      It’s upto you to use these method as per requirement. If youdon’t declare these methods you won’t find any way to set or get value of a property in class.
      Hope it help but i will write a separate article on Java Bean which will cover all these aspects.


  7. Sainath Pawar January 28, 2016 at 7:06 pm - Reply


    Please explain what does synchronized (string.class) mean????

  8. test February 16, 2016 at 6:41 am - Reply

    lookie here

  9. Natty Kish September 10, 2016 at 7:47 am - Reply

    Good Explanation !!!

  10. Sandhya September 26, 2016 at 10:17 am - Reply

    can u send core and advanced java full tutorial materials pls.

    • J Singh September 26, 2016 at 4:29 pm - Reply

      You can buy eBook from top Menu.

  11. SAMIM November 2, 2016 at 6:37 am - Reply


  12. SAMIM November 2, 2016 at 6:38 am - Reply


  13. Anurag Singh July 28, 2017 at 11:01 am - Reply

    This is really nice tutorial about collection

Leave A Comment