This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collections

 
shri Sonparote
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
Please Solve my query about HashMap and TreeMap.
We Can Store null key in HashMap but we can't store
null key in TreeMap It is giving runtime exception.
Why this is so?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15630
46
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TreeMap sorts its elements by key. The map cannot be sorted properly if one of the keys is 'null' - so 'null' is not allowed as a key.
 
shri Sonparote
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
 
shri Sonparote
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you I have one more doubt

Why set.add("sds"); throw java.lang.UnsupportedOperationException
 
Manfred Klug
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by shri Sonparote:
Why set.add("sds"); throw java.lang.UnsupportedOperationException


Have a look at the API documentation of TreeMap.keySet().
 
shri Sonparote
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic