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.
Map
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
:
- HashMap
- LinkedHashMap
- TreeMap
- ConcurrentHashMap
List of articles on Java Map Implementation:
- How does HashMap work internally in Java?
- HashMap vs Hashtable Vs SynchronizedMap Vs ConcurrentHashMap
Set
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
:
- HashSet
- LinkedHashSet
- TreeSet
- 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
Queue
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 ;
- LinkedList
- PriorityQueue
- 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 List, Set, and Map interfaces which take the elements as arguments and return an instance of List, Set and Map respectively. You can read more about it at Convenience Factory Methods for Collections