aspose file tools*
The moose likes Beginning Java and the fly likes Why HashMap contains null key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why HashMap contains null key" Watch "Why HashMap contains null key" New topic
Author

Why HashMap contains null key

Sushil Pathak
Greenhorn

Joined: May 03, 2013
Posts: 1
Hi,
please provide me why HasMap contains one null key and how it can be managed please provide solution with example.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8016
    
  22

Sushil Pathak wrote:please provide me why HasMap contains one null key and how it can be managed please provide solution with example.

First: Welcome to JavaRanch.

Second: In answer to your question - No. That's not how this site works; we expect you to do your own work here.

What I will tell you is that a HashMap (indeed, ANY Map) can only contain one of any key, be it null or anything else. Some Map implementations choose not to allow nulls, and if they don't, there's probably a good reason; but don't expect the designer to tell you. That's what Object-Orientation is all about: hiding information.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Read this thread for a better perspective on this aspect of a HashMap. There are many ways to look at a glass of water. One might say it is half full, another might see it as half empty. It is a design issue that prompted the author of this class to take this step. Joshua would be able to answer your query perfectly.


~ Mansukh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why HashMap contains null key