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

HashMap

 
Ida Achi
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Please explain me the following statement maybe with a code example:

HashMap allows one null key and multiple null values in a collection.


Thank you.
 
Rajeev Rnair
Ranch Hand
Posts: 310
1
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ida Achi wrote:
Please explain me the following statement maybe with a code example:

HashMap allows one null key and multiple null values in a collection.


Thank you.




the above code prints ..
{null=null, 1=null, 2=null, 3=null, 4=null}
Hope this is clear!!!
 
Ida Achi
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks mate. I just get overly confused at times.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The point to remember is that keys in a HashMap must be unique - because of this, there can ofcourse be only one entry in the map which has null as the key.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic