This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Delete some keys-values from a HashMap  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all,
I have a little problem. I use a map of type ConcurrentHashMap to store old filenames and renamed filenames
e.g. Map<String,String> renameMap =......
What i want is how could i delete some key-values in my map(based on some criteria)?Not all.

Thanks in advance
 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't have the key strings that you want to remove, you can obtain an iterator() from the Map and remove mappings selectively as you iterate through all mappings.
 
Sheriff
Posts: 21327
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:you can obtain an iterator() from the Map


Through its entrySet() method yes. Map doesn't have an iterator() method itself (although maybe it should have...).
 
Marshal
Posts: 59090
180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Antonis Kaklis
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all!
 
Campbell Ritchie
Marshal
Posts: 59090
180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Montana has cold dark nights. Perfect for the heat from incandescent light. Tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!