Collections Differences
Collections Differences
List,
java.util.Set and java,util.Map in java
1 Duplicate List allows to Set does not allow to Map stores data in form of
elements store store duplicate elements key-value pair it does not
duplicate in java. allow to store duplicate
elements in keys but allows duplicate
java. values in java.
3 Null keys List allows to Most of the Set Lets look at Map
store many implementations allow to implementations -
null keys in add only one null in java.
java. HashMap allows one null
TreeSet and key and many null values.
ConcurrentSkipListSet LinkedHashMap allows
does not allow to add null one null key and many null
in java. values.
TreeSet doesn’t
allow even a
single null
LinkedHashSet
HashSet allows element. If you try
Null also allows
maximum one to insert null
elements maximum one null
null element. element into
element.
TreeSet, it throws
NullPointerExcepti
on.
LinkedHashMap
TreeMap