• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
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?
 
author
Marshal
Posts: 23439
138
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
 
Marshal
Posts: 58449
178
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!