Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why HashMap contains null key

 
Sushil Pathak
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
please provide me why HasMap contains one null key and how it can be managed please provide solution with example.
 
Winston Gutkowski
Bartender
Pie
Posts: 10422
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic