Set, List and Map are three important interface of Java collection
framework and Difference between Set, List and Map in Java is one of the most
frequently asked Java
Collection interview question. Some time this question is asked as When to
use List, Set and Map in Java.
Clearly, interviewer is looking to know that whether you are familiar with
fundamentals of Java collection framework or not. In order to decide when to
use List, Set or Map , you need
to know what are these interfaces and what functionality they provide. List
in Java provides ordered and indexed collection which may contain
duplicates. Set provides an unordered collection of unique
objects, i.e. Set doesn't allow duplicates, while Map provides a
data structure based on key value pair and hashing. All three List, Set and Map are interfaces
in Java and there are many concrete implementation of them are available in
Collection API. ArrayList
and LinkedList are two most popular used List implementation while LinkedHashSet,
TreeSet and HashSet are frequently used Set
implementation. In this Java article we will see difference between Map, Set and List in Java and learn when to use
List, Set or Map.