“In” Keyword -Groovy

1 min read
Share:
keyword "in"  is used in Groovy to check whether element exists in Collection. 

Example List
[groovy]
String str = "this is me "
List list = str.tokenize(" ")
String word = "this"
assert  word in list == true
assert  "hello" in list == false
[/groovy]

 Example with Set [groovy]
Set set = ["this","is","me"]
String word = "this"
assert  word in set == true
assert  "hello" in set == false
[/groovy]

Leave a Reply

Your email address will not be published. Required fields are marked *

Services