“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
String str = "this is me "
List list = str.tokenize(" ")
String word = "this"
assert  word in list == true
assert  "hello" in list == false

Example with Set

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

Tag -

FOUND THIS USEFUL? SHARE IT

Leave a comment -