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 358 views
4 answers 846 views
1 answer 422 views
2 answers 627 views
2 answers 498 views
498 views asked Oct 4, 2020 by avibootz
1 answer 398 views
398 views asked Oct 5, 2020 by avibootz
1 answer 338 views
338 views asked Oct 5, 2020 by avibootz
...