groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nelson, Erick" <Erick.Nel...@hdsupply.com>
Subject Re: Looping through a hashmap & removing elements
Date Thu, 02 Jun 2016 18:25:04 GMT

Does something like this work?

uidMap.keySet().removeAll(uidMap.findAll{it.key == '?'}.keySet())



From: Guy Matz <guymatz@gmail.com<mailto:guymatz@gmail.com>>
Reply-To: "users@groovy.apache.org<mailto:users@groovy.apache.org>" <users@groovy.apache.org<mailto:users@groovy.apache.org>>
Date: Thursday, June 2, 2016 at 11:18 AM
To: "users@groovy.apache.org<mailto:users@groovy.apache.org>" <users@groovy.apache.org<mailto: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

Mime
View raw message