How to find if value exist in map with Groovy

2 Answers

0 votes
def map = [name: "Groovy", age: 13, country: "United States", city: "New York"]
 
def f = map.find{it.value == "New York"}
println f

f = map.find{it.value == "LA"}
println f
 
  
  
  
/*
run:
  
city=New York
null
  
*/

 



answered Oct 5, 2020 by avibootz
0 votes
def map = [name: "Groovy", age: 13, country: "United States", city: "New York"]
 
def f = map.find{it.value == "New York"}?.value
println f

f = map.find{it.value == "LA"}?.value
println f
 
  
  
  
/*
run:
  
New York
null
  
*/

 



answered Oct 5, 2020 by avibootz

Related questions

1 answer 264 views
4 answers 668 views
1 answer 304 views
2 answers 480 views
2 answers 371 views
371 views asked Oct 4, 2020 by avibootz
1 answer 307 views
307 views asked Oct 5, 2020 by avibootz
1 answer 255 views
255 views asked Oct 5, 2020 by avibootz
...