• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can you removed Key-Value pairs from hashmap based on finding the value?  RSS feed

 
Ted Schrey
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
key = a name
value = a number

if given the number, can I find and delete the set from a HashMap?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ted Schrey wrote:
if given the number, can I find and delete the set from a HashMap?


Sure. Get the entry set. Iterate through the entry set. And delete the entries whose value match what you want to delete. Also, remember that there may be more than one entry that matches the value that you want to delete.

Henry
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Map interface has a remove method which may also do what you want. Beware: that method is overloaded.
 
Ted Schrey
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! That did it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!