This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

null as key in HashMap ?  RSS feed

 
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: 4568
9
  • 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
Boost this thread!