I know Set and Map accepts null values and today I just found out LinkedList also accepts null values like
map.put(null, 1);
set.add(null);
linkedList.add(null)
Is there any other collections that allow null values to be stored?. Just posting to get a comprehensive list in one place and reason for each for them.
Set
and Map
are interfaces. They have several implementations in Java.
Popular implementations of the Map
are:
HashMap
- accepts one null
keyHashtable
- doesn't accept any null
keyTreeMap
- doesn't accept any null
keyLinkedHashMap
- accepts one null
keyAny number of null
values can be added as value in any of above implementations
Popular implementations of the Set
are:
HashSet
- accepts one null
elementTreeSet
- doesn't accept any null
elementLinkedHashSet
- accepts one null
elementAny implementations of List
, like ArrayList
or LinkedList
can accept null
s.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With