“In” Keyword -Groovy « Intelligrape Groovy & Grails Blogs

“In” Keyword -Groovy

Posted by Hitesh Bhatia
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
  • Share/Bookmark
This entry was posted on November 29th, 2010 at 2:00 am and is filed under Grails, Groovy . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply