“In” Keyword -Groovy

29 / Nov / 2010 by Hitesh Bhatia 0 comments
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]

FOUND THIS USEFUL? SHARE IT

Leave a Reply

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