• Post Reply Bookmark Topic Watch Topic
  • New Topic

removing elements from hashmaps  RSS feed

 
sandy Bond
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i was wondering if anybody could tell me how to remove a hashmap mapping without knowing the key for that mapping. for info the scenario is a text base adventure game. I have implemented hashMaps, one to hold items that the player picks up and the other to hold the items in the current room.
Or even batter might be any ideas on moving objects between hashMaps.
Thanks
 
paul wheaton
Trailboss
Posts: 22577
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you ask your object for it's key?
 
paul wheaton
Trailboss
Posts: 22577
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure that what you don't really need is a set? So a "dude" has a set of objects.
HashMap is more for lookups. Like the string "goat" will return the Animal object that is configured with goat information.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!