Hell yeah there's a Groovy-er (and safer) way:
uidMap = uidMap.findAll { key, value ->
// return true if you want to keep the entry, false to exclude it
}
Notice that this produces a new Map, leaving the original unchanged. Even
though in the example I reuse the variable name.
http://groovy-lang.org/gdk.html
On Jun 2, 2016 2:18 PM, "Guy Matz" <[email protected]> wrote:
> Hi! I want to loop through a hashmap and delete some elements based on
> some criteria . . . I thought there would be some slick groovy method - in
> the spirit of findAll, etc. - to do this, but couldn't find it . . . my
> java developer workmate suggested:
>
> iter = uidMap.entrySet().iterator()
> while (iter.hasNext()) {
> entry = iter.next()
> key = entry.key
> value = entry.value
>
> if (bla, blah, blah) {
>
> iter.remove()
>
> }
>
>
> Is there a groovier way?
>
>
> Thanks!
>
> Guy
>
>