groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guy Matz <guym...@gmail.com>
Subject Re: Looping through a hashmap & removing elements
Date Thu, 02 Jun 2016 18:56:03 GMT
Ahh!!  I only saw this removeAll:
public boolean *removeAll*(Object[]
<http://docs.oracle.com/javase/7/docs/api/java/lang/Object[].html> items)

!!  Thanks!!!

On Thu, Jun 2, 2016 at 2:27 PM, Winnebeck, Jason <
Jason.Winnebeck@windstream.com> wrote:

> If you want to actually edit the original map:
>
>
>
> def uidMap = [
>
>   a: 123,
>
>   b: 456,
>
>   c: 789
>
> ]
>
>
>
> uidMap.entrySet().removeAll { it.key.startsWith('a') }
>
>
>
> If you want a new map, emmanuel’s solution using findAll is best.
>
>
>
> Jason
>
>
>
> *From:* Guy Matz [mailto:guymatz@gmail.com]
> *Sent:* Thursday, June 02, 2016 2:18 PM
> *To:* users@groovy.apache.org
> *Subject:* Looping through a hashmap & removing elements
>
>
>
> 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
>
> ------------------------------
> This email message and any attachments are for the sole use of the
> intended recipient(s). Any unauthorized review, use, disclosure or
> distribution is prohibited. If you are not the intended recipient, please
> contact the sender by reply email and destroy all copies of the original
> message and any attachments.
>

Mime
View raw message