Thursday, 17 January 2019

Groovy: Membership Operator


Membership operator (in) is used to check whether given object is present in the collection or not.

HelloWorld.groovy
myHobbies = ["Football", "Cricket", "Chess", "Cycling"]

println "is Football my hobby : ${'Football' in myHobbies}"
println "is Hockey my hobby : ${'Hockey' in myHobbies}"

Output
is Football my hobby : true
is Hockey my hobby : false

Previous                                                 Next                                                 Home

No comments:

Post a Comment