• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

null as key in HashMap ?

 
Ranch Hand
Posts: 72
Android Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 99
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic