Difference b w List Set and Map - ayushmathur94/DirectQuesAns_Prep GitHub Wiki

List

Set

Map

1.   The list interface allows duplicate elements

Set does not allow duplicate elements.

The map does not allow duplicate elements

2.   The list maintains insertion order.

Set do not maintain any insertion order. 

The map also does not maintain any insertion order. 

3.   We can add any number of null values.

But in set almost only one null value.

The map allows a single null key at most and any number of null values.


4.   List implementation classes are Array List, LinkedList.

Set implementation classes are HashSet, LinkedHashSet, and TreeSet. 

Map implementation classes are HashMap, HashTable, TreeMap, ConcurrentHashMap, and LinkedHashMap.

5.   The list provides get() method to get the element at a specified index.

Set does not provide get method to get the elements at a specified index

The map does not  provide get method to get the elements at a specified index

6.   If you need to access the elements frequently by using the index then we can use the list

If you want to create a collection of unique elements then we can use set

If you want to store the data in the form of key/value pair then we can use the map.

7.   To traverse the list elements by using Listlterator.

Iterator can be used traverse the set elements

Through keyset, value, and entry set.

⚠️ **GitHub.com Fallback** ⚠️