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 332 views
1 answer 524 views
1 answer 384 views
1 answer 428 views
1 answer 381 views
1 answer 407 views
407 views asked Oct 5, 2020 by avibootz
1 answer 346 views
346 views asked Oct 5, 2020 by avibootz
...