Win a copy of Java by Comparison (eBook) this week in the Java in General 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: 21255
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...).
 
Sheriff
Posts: 57778
178
  • 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
Sheriff
Posts: 57778
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!