| Author |
Why HashTable does not allow null values..?
|
santhosh.R gowda
Ranch Hand
Joined: Apr 06, 2009
Posts: 296
|
|
Dear all
As we know that Hashtable does not allow null values as keys and values,Kindly tell me why they made the implementation like that other than Hashmap which allows null
[Jesper Young: edited topic title, "numm" -> "null"]
|
Creativity is nothing but Breaking Rules
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56221
|
|
"numm value"? Please take the time to proof-read your posts.
Of what utility would they be? Null values would be indistinguishable from missing values except during iteration, and of what use would a null key be?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
santhosh.R gowda
Ranch Hand
Joined: Apr 06, 2009
Posts: 296
|
|
|
Sorry for the misplacing of numm instead of null
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Bear Bibeault wrote:Null values would be indistinguishable from missing values except during iteration
That's where containsKey comes in.
and of what use would a null key be?
It allows you to store the key without a value. Granted, I never saw the need for that, but still.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
santhosh.R gowda
Ranch Hand
Joined: Apr 06, 2009
Posts: 296
|
|
I want the reason behind that why they made to allow null values in hashmap i had gone through the API that while putting they are going to check the null values.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
I think the more important question is: why would you NOT want to allow null keys and values? Using null values for defaults (if there is no value for a non-null key, check the value for the null key) isn't uncommon. If you want to disallow them, use Collections.checkedMap - that one forbids null as well.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
|
Agree with Rob; there are instances where you want to permit nulls and instances when you want to prohibit them.
|
 |
 |
|
|
subject: Why HashTable does not allow null values..?
|
|
|