This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HashMap look for help  RSS feed

 
Hui Zhao
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a HashMap sta. I tried to get the key value according to the value.

HEEP NEEDED! THANKS
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maps hold key/value pairs. The method containsValue() checks values, while get() accepts a key. You want "containsKey()".
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll also want to swap String and Double in the map declaration.

If not then you have to remember one thing: what is the key for any double value? Because mulitple keys can have the same value. If that's the case for your specific double, then which of the keys do you need?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!