M. Dylan
0
Q:

when to use list set map

When to use List, Set and Map?
If we need to access elements frequently by using index, then List is a way 
to go ArrayList provides faster access if we know index.
If we want to store elements and want them to maintain an order, 
then go for List again. List is an ordered collection and maintain order.
If we want to create collection of unique elements and don't want
any duplicate than choose any Set implementation. (HashSet... )
If we want store data in form Key and Value than Map is the way to go.
We can choose from HashMap, Hashtable...
0
Set is unordered
List is ordered collection, based on zero based index.
List allow duplicate elements
Set does not allow duplicates.
List does not prevent inserting null elements (as many you like),
Set will allow only one null element.
The List and Set both extend the collection interface. However, there are some
differences between the both which are listed below.
The List can contain duplicate elements whereas Set includes unique items.
The List is an ordered collection which maintains the insertion order whereas 
Set is an unordered collection which does not preserve the insertion order.
The List interface contains a single legacy class which is Vector class
whereas Set interface does not have any legacy class.
The List interface can allow n number of null values whereas
Set interface only allows a single null value.
0
List is collection of elements whereas map is collection of key-value pairs.
0

New to Communities?

Join the community