Code Pumpkin

Java Collection

Collection framework has its own importance as it deals with the datastructure of the language. Java Collection classes are heart of Java API.   It is essential to use built-in java collections like HashMap, ArrayList or LinkedList for accessing, storing and processing data in java applications. Below are set of articles which covers the essential topics from collection framework.


java.util.Map interface is used to map unique keys to values i.e. (key,value). Given a key and a value, you can store the value in a Map object. After the value is stored, you can retrieve it by using its key. Map is not considered to be a true collection, as the Map interface does not extend the Collection interface. Instead, it starts an independent branch in the Java Collections Framework. Here are some of the implementation of java.util.Map:

  1. ​HashMap
  2. LinkedHashMap
  3. TreeMap
  4. ConcurrentHashMap

List of articles on Java Map Implementation:

  1. How does HashMap work internally in Java?
  2. HashMap vs Hashtable Vs SynchronizedMap Vs ConcurrentHashMap


A Set is a Collection that cannot contain duplicate elements. It models the mathematical set abstraction.  Here are some of the implementations of java.util.Set:

  1. ​HashSet
  2. LinkedHashSet
  3. TreeSet
  4. CopyOnWriteArraySet

From above four, first three Set implementation internally uses corresponding Map implementations as backing datastructures e.g. Backing datastructure of HashSet is HashMap and TreeSet is TreeMap. You can learn more about these internal implementations at

  1. How is HashSet implemented internally in Java?
  2. Performance Issue with HashSet RemoveAll() method


The java.util.Queue is a child interface of java.util.Collection interface. Queue typically orders elements in FIFO (First In First Out) manner. However, this behaviour is not mandatory. priorityQueue implementation orders elements according to supplied Comparator or natural Ordering (using Comparable). Here is the list of some of the Java Queue implementations ;

  1. LinkedList
  2. PriorityQueue
  3. BlockingQueue – Producer Consumer Design Pattern

Java 8 Updates

Java Stream API is one of the important feature introduced in Java 8 along with Lamba Expressions. Stream is not exactly the collection. Java Stream doesn't store data, it operates on the source data structure (collection and array) and produce pipelined data that we can use and perform specific operations. Learn more about it at Stream API – Stream Collection Type

Java 9 updates

Java is often criticized for its verbosity. Creating a small, unmodifiable collection (say, a set) involves lots of code. To overcome this in Java 9, static methods have been introduced on ListSet, and Map interfaces which take the elements as arguments and return an instance of ListSet and Map respectively. You can read more about it at Convenience Factory Methods for Collections

Total Posts : 124
follow us in feedly

Like Us On Facebook