Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes HashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HashMap" Watch "HashMap" New topic
Author

HashMap

Ravi Kiran
Greenhorn

Joined: Jan 07, 2007
Posts: 29
Hi,

Can any one please explain me why hashmap is allowing a single null key, whats the benefit by having a single null key?
Vinoth Kumar Kannan
Ranch Hand

Joined: Aug 19, 2009
Posts: 276

Ravi, you know what...I too was wondering what the answer might be and did a google on this. To my surprise, the first link was from CodeRanch. This seems to have been already discussed here. A convincingly good thread, actually..
http://www.coderanch.com/t/385836/java/java/Why-HashMap-allows-add-one


OCPJP 6
Ravi Kiran
Greenhorn

Joined: Jan 07, 2007
Posts: 29
Thanks alot vinoth,

a very useful link you posted..


Thanks,
Ravi
Vinoth Kumar Kannan
Ranch Hand

Joined: Aug 19, 2009
Posts: 276

You're welcome
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38016
    
  22
We only have good threads here (and if you believe that, you will believe anything )

HashMap is a library class; as people implied on that thread, a library class should be provided with all possible actions, As Joanne Neal (who is an asset to this website) said, it is easy to wrap HashMap to prohibit null keys (or also prohibit null values) but not to permit nulls if the enclosed class prohibits nulls.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3429
    
  12
Campbell Ritchie wrote:Joanne Neal (who is an asset to this website)


Careful. You'll have Rob complaining about us flirting again. You know how jealous he gets.


Joanne
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38016
    
  22
Jealous of whom?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19653
    
  18

Meh, I know Campbell is already happily married. Besides, my girlfriend won't allow me to become jealous


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3429
    
  12
Rob Prime wrote:Besides, my girlfriend won't allow me to become jealous


I'm glad to know she's got you so well trained.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HashMap
 
Similar Threads
EXCEPT SYNCHRONIZATION what are the main diff between ArrayList and Vector
what's the difference between hashtable and hashMap
advantage of hashmap over hashtable
hashmap with null values and keys
null key in a HashMap