• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

null as key in HashMap ?

 
Suhas Mandrawadkar
Ranch Hand
Posts: 72
Android Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Source: http://www.javacertifications.net/javacert/scjp1.6Mock.jsp



But on KB book it says, HashMap allows one null key and multiple null values in a collection.

Map being created is HashMap please explain.
 
Matthew Brown
Bartender
Posts: 4566
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But it's not a HashMap that's causing the error, is it? It's an EnumMap. Check the documentation for that class.
 
Anuj Prashar
Ranch Hand
Posts: 99
Android Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are inserting null key in object of type EnumMap and as per api doc of EnumMap null key are not permitted.
See
http://download.oracle.com/javase/1.5.0/docs/api/java/util/EnumMap.html
 
Suhas Mandrawadkar
Ranch Hand
Posts: 72
Android Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anuj Prashar wrote:You are inserting null key in object of type EnumMap and as per api doc of EnumMap null key are not permitted.
See
http://download.oracle.com/javase/1.5.0/docs/api/java/util/EnumMap.html#EnumMap%28java.util.Map%29


Oops, yeah. Its EnumMap. Now that's new Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic