Anyone removed entries from a map, e.g. one built from a json string, using a pattern / condition on the key value?
I've read the JSON below into a map and can't seem to get the removeAll function to work like some online examples explain for Groovy. I want to remove all the "image" entries or all the "background" entries. Any tips?
Hmmm... Still a little unsure what you mean, if I want to remove all entries from the Map with a prefix of "image" or a prefix of "background" as the key value, any tips on how to apply the stack overflow example?
Probably worth emphasising this is a map and not a list... Am guessing you / they mean to get the keyset to use in the function...
And thanks for responding btw, sounds a little demanding in my initial response...
That's what I would have thought would work.... Can only hope my attention to detail is not what it should be, and I will correct this during more more appropriate hours later this morning....
(Fwiw, if you want to remove items from the map you are iterating over, that's a bit of a problem (untill remove all is introduced). So you'll have to resort to cloning up front or so. )
The one I posted worked when I tested it. I would do what @thebearmay posted in place of the substring part in my demo, since his is more intuitive (and therefore less error prone).
Back home. Just to ("probably" unnecessarily ) elaborate. Here is a version that removes the items from the original Map instance. (it works as findAll returns a new Map instance)
Not that the other options don't work, but was able to get the findAll setup working from @jasper 's last post, thanks for that.
EDIT: Also funny that I now look back at the scraping of the shtml file I use as the source of the radar image links.... using a little known function over a map... called findAll()....