Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing map values associated with the key  RSS feed

 
Rickey Fuller
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code, but I am struggling with part of the question. The keys are the names and the values are their interests. I have to add a public method called printMapValue() which takes 1 argument and returns no value. If the key is in the map, then it prints out the values associated with it. Every time I run it, it prints out the key instead of the value. I know the solution is going to be really simple, but I just can't see it. Any help will be appreciated




Every time I run it, it prints out the key instead of the value.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So where in this statementdoes the value returned by the get() method get stored?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And this is a great example of where naming matters. Using the variable name value to store the key, is one of the worst choices you could have made.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!