How to retain all element that satisfy a condition from a map in Groovy

1 Answer

0 votes
def map = [a:13, b:12, c:43, d:87, e:2, f:100, g:99]

map.retainAll{e -> e.value % 2 == 0}

map.each{key, value -> println "${key}:${value}"}

 
 
 
/*
run:
 
b:12
e:2
f:100
 
*/

 



answered Oct 4, 2020 by avibootz

Related questions

1 answer 235 views
1 answer 414 views
1 answer 264 views
1 answer 304 views
1 answer 285 views
1 answer 308 views
308 views asked Oct 5, 2020 by avibootz
1 answer 257 views
257 views asked Oct 5, 2020 by avibootz
...