aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes null as key in HashMap ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "null as key in HashMap ?" Watch "null as key in HashMap ?" New topic
Author

null as key in HashMap ?

Suhas Mandrawadkar
Ranch Hand

Joined: Jul 21, 2007
Posts: 72

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.


Regards, Suhas S. Mandrawadkar.
Certifications: SCJP 6, SCWCD 5, Oracle WebLogic Server Administrator, OCE Java EE 6 EJB Developer
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4490
    
    8

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

Joined: Apr 15, 2008
Posts: 99

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


SCJP 5,SCWCD 5, RHCT
Suhas Mandrawadkar
Ranch Hand

Joined: Jul 21, 2007
Posts: 72

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: null as key in HashMap ?