Mitin .It
Mitin .It
Java Collections can achieve all the operations that you perform on a data such as
searching, sorting, insertion, manipulation, and deletion.
List
A List in java extends the collection interface and represent an
sequenced or ordered group of elements. It can contain duplicate
elements. It also defines some additional methods which it inherits
from Collection interface.
Note: Set interface does not have any additional method other
than methods inherited from Collection interface. With all
collection interface methods it adds the restriction that it can
not contain a duplicate elements.
Map
A map in java, not extends the Collection interface. It represents a
group of special elements or objects. Every map element or object
contains key and value pair. A map can’t contain duplicate keys and
one key can refer to at most one value.
Difference between List, Set, and Map in Java
List Set Map
The list
interface
Set does not allow
allows The map does not allow duplicate elements
duplicate elements.
duplicate
elements
The list
maintains Set do not maintain The map also does not maintain any
insertion any insertion order. insertion order.
order.
We can
add any But in set almost only The map allows a single null key at most
number of one null value. and any number of null values.
null values.
List
implement Set implementation
ation classes Map implementation classes
classes are HashSet, Linked are HashMap, HashTable, TreeMap, Conc
are Array HashSet, urrentHashMap, and LinkedHashMap.
List, Linked and TreeSet.
List.
The list
provides
get() Set does not provide
method to get method to get the The map does not provide get method to
get the elements at a get the elements at a specified index
element at specified index
a specified
index.
If you need If you want to create If you want to store the data in the form of
to access a collection of unique key/value pair then we can use the map.
List Set Map
the
elements
frequently
by using elements then we can
the index use set
then we
can use
the list
To traverse
the list Iterator can be used
elements traverse the set Through keyset, value, and entry set.
by using elements
Listlterator.